Skip to content

Instantly share code, notes, and snippets.

@apptects
Created April 8, 2019 09:20
Show Gist options
  • Select an option

  • Save apptects/1982ad378681f515dc73b55cd77f648d to your computer and use it in GitHub Desktop.

Select an option

Save apptects/1982ad378681f515dc73b55cd77f648d to your computer and use it in GitHub Desktop.
Redux Reducer
AppState reducer(AppState oldState, dynamic action) {
if(action is ChangeSearchTextAction) {
return oldState.copyWith(searchText: action.searchText);
} else if (action is UpdateTrackItemsAction) {
return oldState.copyWith(trackItems: action.trackItems);
} else if (action is PlayAudioUrlAction) {
return oldState.copyWith(activePlayingAudioUrl: action.audioUrl);
} else if (action is StopAudioAction) {
return oldState.copyWith(activePlayingAudioUrl: '');
} else if (action is CompletedAudioAction) {
return oldState.copyWith(activePlayingAudioUrl: '', currentAudioDuration: Duration());
} else if (action is AudioDurationChangedAction) {
return oldState.copyWith(currentAudioDuration: action.duration);
} else if (action is AlbumDetailsAction) {
return oldState.copyWith(albumId: action.albumId);
} else if (action is AlbumTrackItemsAction) {
return oldState.copyWith(albumItems: action.trackItems, albumReleaseDate: action.albumReleaseDate);
}
return oldState;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment