// Copyright (c) 2016, Pavlo Aksonov // All rights reserved. import {State, StateMachine, Transition} from 'statem'; import {action, computed, observable} from 'mobx'; {{#states }} export class {{ id }}State extends State { {{#parentProps}} get {{ id }}() { return this.parent.{{id}} }; set {{ id }}(value) { this.parent.{{id}} = value }; {{/parentProps}} {{#vars}} @computed get {{ id }}() { return {{ value }} }; {{/vars}} {{#props }} @observable {{ id }}; {{/props}} constructor(_, parent, sm){ super({ id: "{{id}}"}, parent, sm); {{# parentProps }} const {{ id }} = this.{{ id }}; {{/parentProps}} {{# vars}} const {{ id }} = this.{{ id }}; {{/vars}} {{#props}} let {{ id }} = {{& value }}; this.{{ id }} = {{id}}; {{/props}} let states = []; {{#states}} states.push(new {{id}}State(null, this, sm)); {{/states}} let transition = []; {{#transitions }} transition.push({ {{# event}} event: "{{event}}", {{/event}} {{# type}} type: "{{type}}", {{/type}} {{# mode}} mode: "{{mode}}", {{/mode}} {{# cond}} cond: {{& cond}}, {{/cond}} {{# target}} target:"{{ target }}", {{/target}} {{# ontransition}}ontransition:{{& ontransition}}, {{/ ontransition}} }); {{/transitions}} this.states = states; this.transitions = transition.map(el => new Transition(this, el)); {{# params }}this.{{key}} = {{& value}}; {{/params}} if (this.states && this.states.length){ const initial = this.initial || this.states[0].id; this.push({id: initial}); {{# isSwitch }} this.isSwitch = true; for (let i=0;i { this.handle("{{ name }}", data); }; {{/methods}} } {{/states}} export class Statem extends StateMachine { {{#states}} get {{ lid }}(): {{id}}State {return this.getState("{{id}}")}; {{/states}} } export default new Statem(null, __RootState);