Skip to content

Instantly share code, notes, and snippets.

@craigomac
Created June 11, 2019 10:49
Show Gist options
  • Save craigomac/f7f7854e2ad1160879d439ea5016e0c5 to your computer and use it in GitHub Desktop.
Save craigomac/f7f7854e2ad1160879d439ea5016e0c5 to your computer and use it in GitHub Desktop.
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