-
Notifications
You must be signed in to change notification settings - Fork 710
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Organized reducers and middlewares to appropriate places.
- Loading branch information
Iiro Krankka
committed
Apr 10, 2018
1 parent
01ef9f9
commit c7d3fc9
Showing
12 changed files
with
63 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import 'package:inkino/data/models/actor.dart'; | ||
import 'package:inkino/redux/actor/actor_actions.dart'; | ||
import 'package:redux/redux.dart'; | ||
|
||
final actorReducer = combineTypedReducers<Map<String, Actor>>([ | ||
new ReducerBinding<Map<String, Actor>, ActorsUpdatedAction>(_actorsUpdated), | ||
new ReducerBinding<Map<String, Actor>, ReceivedActorAvatarsAction>(_receivedAvatars), | ||
]); | ||
|
||
Map<String, Actor> _actorsUpdated(Map<String, Actor> actorsByName, action) { | ||
var actors = <String, Actor>{}..addAll(actorsByName); | ||
action.actors.forEach((actor) { | ||
actors.putIfAbsent(actor.name, () => new Actor(name: actor.name)); | ||
}); | ||
|
||
return actors; | ||
} | ||
|
||
Map<String, Actor> _receivedAvatars(Map<String, Actor> actorsByName, action) { | ||
var actorsWithAvatars = <String, Actor>{}..addAll(actorsByName); | ||
action.actors.forEach((actor) { | ||
actorsWithAvatars[actor.name] = new Actor( | ||
name: actor.name, | ||
avatarUrl: actor.avatarUrl, | ||
); | ||
}); | ||
|
||
return actorsWithAvatars; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,16 @@ | ||
import 'package:inkino/data/models/actor.dart'; | ||
import 'package:inkino/redux/app/app_actions.dart'; | ||
import 'package:inkino/redux/actor/actor_reducer.dart'; | ||
import 'package:inkino/redux/app/app_state.dart'; | ||
import 'package:inkino/redux/event/event_reducer.dart'; | ||
import 'package:inkino/redux/search/search_reducer.dart'; | ||
import 'package:inkino/redux/show/show_reducer.dart'; | ||
import 'package:inkino/redux/theater/theater_reducer.dart'; | ||
import 'package:redux/redux.dart'; | ||
|
||
AppState appReducer(AppState state, dynamic action) { | ||
return new AppState( | ||
searchQuery: _searchQueryReducer(state.searchQuery, action), | ||
searchQuery: searchQueryReducer(state.searchQuery, action), | ||
actorsByName: actorReducer(state.actorsByName, action), | ||
theaterState: theaterReducer(state.theaterState, action), | ||
showState: showReducer(state.showState, action), | ||
eventState: eventReducer(state.eventState, action), | ||
); | ||
} | ||
|
||
String _searchQueryReducer(String searchQuery, action) { | ||
if (action is SearchQueryChangedAction) { | ||
return action.query; | ||
} | ||
|
||
return searchQuery; | ||
} | ||
|
||
final actorReducer = combineTypedReducers<Map<String, Actor>>([ | ||
new ReducerBinding<Map<String, Actor>, ActorsUpdatedAction>(_actorsUpdated), | ||
new ReducerBinding<Map<String, Actor>, ReceivedActorAvatarsAction>(_receivedAvatars), | ||
]); | ||
|
||
Map<String, Actor> _actorsUpdated(Map<String, Actor> actorsByName, action) { | ||
var actors = <String, Actor>{}..addAll(actorsByName); | ||
action.actors.forEach((actor) { | ||
actors.putIfAbsent(actor.name, () => new Actor(name: actor.name)); | ||
}); | ||
|
||
return actors; | ||
} | ||
|
||
Map<String, Actor> _receivedAvatars(Map<String, Actor> actorsByName, action) { | ||
var actorsWithAvatars = <String, Actor>{}..addAll(actorsByName); | ||
action.actors.forEach((actor) { | ||
actorsWithAvatars[actor.name] = new Actor( | ||
name: actor.name, | ||
avatarUrl: actor.avatarUrl, | ||
); | ||
}); | ||
|
||
return actorsWithAvatars; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class SearchQueryChangedAction { | ||
SearchQueryChangedAction(this.query); | ||
final String query; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:inkino/redux/search/search_actions.dart'; | ||
|
||
String searchQueryReducer(String searchQuery, action) { | ||
if (action is SearchQueryChangedAction) { | ||
return action.query; | ||
} | ||
|
||
return searchQuery; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/redux/app/app_reducer_test.dart → test/redux/actor/actor_reducer_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters