Module.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React, {Fragment} from 'react';
  2. import { View } from 'react-native';
  3. import { Resolver } from './Types';
  4. import Injection from './systems/InjectionSystem';
  5. // EventSystem
  6. export default class Module extends React.Component{
  7. constructor(props) {
  8. super(props);
  9. this.Core = Injection.inject('Core');
  10. this.Modules = Injection.inject('Modules');
  11. let {
  12. ModuleID,
  13. EventSystem
  14. } = props;
  15. let eventName = ModuleID + "HitCheck"
  16. EventSystem && EventSystem.on(eventName, ({x,y}) => {
  17. return true;
  18. });
  19. this.isTemplate = false
  20. //console.log("GEN EV: " , eventName, EventSystem);
  21. this._containerStyle = {
  22. marginLeft: 24,
  23. marginRight: 24
  24. }
  25. this.counter = 0;
  26. }
  27. getId() {
  28. return this.props.ModuleID;
  29. }
  30. renderModule(ctor, namespace = "default", props = {}) {
  31. let VS = this.props.CoreSystem.ViewSystem;
  32. if(!this.props.CoreSystem.ModuleSystem.get(ctor, namespace)) return null;
  33. return VS.renderModule({
  34. value: ctor,
  35. namespace,
  36. props
  37. }, this.getId() +"C"+ (this.counter++));
  38. }
  39. createAction(action) {
  40. if(!this.props.CoreSystem) {
  41. console.warn("This module was constructed without a CoreSystem");
  42. return;
  43. }
  44. return this.props.CoreSystem.ActionSystem.createAction(action);
  45. }
  46. setContainerStyle(style) {
  47. this._containerStyle = style;
  48. }
  49. display() {
  50. throw new Error("You must extend this base Module and override display method!");
  51. }
  52. module(mod, props) {
  53. return mod ?
  54. this.renderModule(mod.value, mod.namespace, props) : null;
  55. }
  56. moduleArray(modules, props) {
  57. return modules ? modules.map((mod) => this.module(mod,props)) : null;
  58. }
  59. render() {
  60. this.counter = 10100;
  61. return <View ModuleID={this.props.ModuleID} style={[{overflow:'hidden'}]} MY_WRAPPER_FROM_BASE_MODULE={true}>
  62. {this.display()}
  63. </View>
  64. // throw new Error("You must extend this base Module and override render method!");
  65. }
  66. getProps() {
  67. return Resolver(this.constructor.Inputs, this.props);
  68. }
  69. }