Created
June 11, 2019 10:49
-
-
Save craigomac/f7f7854e2ad1160879d439ea5016e0c5 to your computer and use it in GitHub Desktop.
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
class AssetsPrepareLevelsAction { } | |
class AssetMiddleware implements MiddlewareClass<AppState> { | |
final String pathToAssets; | |
AssetMiddleware(this.pathToAssets); | |
@override | |
Future call(Store<AppState> store, action, NextDispatcher next) async { | |
if (action is AssetsPrepareLevelsAction) { | |
String pathToLevels = await Asset("$pathToAssets/levels", "levels").prepare(); | |
String levelsString = await File(pathToLevels).readAsString(); | |
List<dynamic> levelsJson = jsonDecode(levelsString); | |
store.dispatch(LoadLevelsAction(Level.levelHeirarchyFromJson(levelsJson))); | |
} | |
next(action); // don't forget, since other middlewares might look at this action | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment