| 613 | } |
| 614 | |
| 615 | function build(target, config) { |
| 616 | if ((typeof target !== 'object') || Array.isArray(target)) |
| 617 | throw Error('StateMachine can only be applied to objects'); |
| 618 | plugin.build(target, config); |
| 619 | Object.defineProperties(target, PublicProperties); |
| 620 | mixin(target, PublicMethods); |
| 621 | mixin(target, config.methods); |
| 622 | config.allTransitions().forEach(function(transition) { |
| 623 | target[camelize(transition)] = function() { |
| 624 | return this._fsm.fire(transition, [].slice.call(arguments)) |
| 625 | } |
| 626 | }); |
| 627 | target._fsm = function() { |
| 628 | this._fsm = new JSM(this, config); |
| 629 | this._fsm.init(arguments); |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | //----------------------------------------------------------------------------------------------- |
| 634 | |