3
0

ActionSystem.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import RoutingSystem from './RoutingSystem.js';
  2. import ViewSystem, { View } from './ViewSystem.js';
  3. import ModuleSystem from './ModuleSystem.js';
  4. import Modules from '../../modules';
  5. import EventSystem from './EventSystem';
  6. import * as Font from 'expo-font';
  7. export default class ActionSystem {
  8. constructor(CS) {
  9. // TODO -- Make correct Initialization
  10. this.CoreSystem = CS;
  11. this.EventSystem = new EventSystem();
  12. this.events = [...ActionSystem.Actions];
  13. this._disabled = false;
  14. this.setupEvents();
  15. }
  16. setupEvents() {
  17. this.events.map((Action) => {
  18. this.EventSystem.on(Action.id, (d) => this.dispatch(Action, d));
  19. });
  20. }
  21. dispatch(Action, data) {
  22. return !this._disabled && new Action(this.CoreSystem).run(data)
  23. }
  24. disable() {this._disabled = true;}
  25. enable() {this._disabled = false;}
  26. toggle() {this._disabled = !this._disabled;}
  27. createAction(action) {
  28. if (!action.type) return;
  29. this.EventSystem.emit(action.type, action.data);
  30. }
  31. onUpdate(fn) {this._onUpdate = fn;}
  32. forceUpdate() {
  33. this._onUpdate && this._onUpdate();
  34. }
  35. }
  36. export class RouteAction {
  37. constructor(CS) {
  38. this.CoreSystem = CS;
  39. }
  40. run(data) {
  41. let {
  42. route
  43. } = data;
  44. if(route)
  45. this.CoreSystem.goto(route);
  46. }
  47. }
  48. RouteAction.id = "changeRoute";
  49. ActionSystem.RouteAction = RouteAction;
  50. ActionSystem.Actions = [
  51. RouteAction
  52. ];