{"_id":"statechart","_rev":"20-46edb5ef428eb4fde0bf702e8777a03d","name":"statechart","description":"StateChart implementation.","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"statechart","version":"0.1.0","description":"StateChart implementation.","homepage":"http://github.com/DavidDurman/statechart/","keywords":["statechart","state machine"],"contributors":[{"name":"David Durman","email":"daviddurman@gmail.com","url":"http://www.daviddurman.com"}],"repository":{"type":"git","url":"git://github.com/DavidDurman/statechart.git"},"bugs":{"web":"http://github.com/DavidDurman/statechart/issues/","mail":"daviddurman@gmail.com"},"directories":{"doc":"./doc","lib":"./lib","test":"./test"},"main":"./lib/statechart","scripts":{"test":"node test/all.js"},"engines":["v8","ejs","node","rhino","browser"],"licenses":[{"type":"GPL 2.0"}],"_id":"statechart@0.1.0","_nodeSupported":true,"_npmVersion":"0.2.7-2","_nodeVersion":"v0.3.1-pre","dist":{"tarball":"https://registry.npmjs.org/statechart/-/statechart-0.1.0.tgz","shasum":"53c1d47f0596e55a32b6330b6228dd1958c4e904","integrity":"sha512-MXOUHQjkft8dNmnGy4mu3p5fYY8e2DtobYiYqeYq/aE8CVzWOext0TeSLN90vuQs334kMC8AeNxJgIHztie+NA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC0ou9sAXsVBf0z+hgV3FhpB9kOypttV3oTBrfKYC+DeAIhAIYv92d5CcZZJeYcwuTUblQS1FZJMHK9rGL0XHtmnSFW"}]}},"0.1.1":{"name":"statechart","version":"0.1.1","description":"StateChart implementation.","homepage":"http://github.com/DavidDurman/statechart/","author":{"name":"David Durman","email":"daviddurman@gmail.com"},"keywords":["statechart","state machine"],"repository":{"type":"git","url":"https://github.com/DavidDurman/statechart.git"},"bugs":{"url":"http://github.com/DavidDurman/statechart/issues/"},"directories":{"doc":"./doc","lib":"./lib","test":"./test"},"main":"./lib/statechart.js","scripts":{"test":"./node_modules/mocha/bin/mocha --reporter spec"},"engines":["v8","ejs","node","rhino","browser"],"licenses":[{"type":"MIT"}],"devDependencies":{"underscore":"~1.4.3","expect.js":"~0.2.0","mocha":"~1.8.1"},"dependencies":{},"readme":"Statechart implementation in JavaScript.\n========================================\n\n[![Build Status](https://travis-ci.org/DavidDurman/statechart.png?branch=master)](http://travis-ci.org/DavidDurman/statechart)\n\nFeatures\n--------\n\n * Hierarchical states\n * Can be mixined with an arbitrary object\n * JSON-like description of the machine\n * Fast\n * Lightweight (4.6KB minified using jsmin)\n * JavaScript engine independent (browsers, nodejs, narwhal, ...)\n\nRelated work\n------------\n\nThis hierarchical state machine implementation has been inspired\nby the QP active object framework, see http://www.state-machine.com/.\n\nDefining a basic state machine\n-------------------------------\n\nState machine is defined as an object with `initialState` and `states` properties. The former defines\nthe first state we want our machine to enter. The latter is an object with states, events and actions:\n\n[![Light switch statechart](http://figurepool.com/figure/view/7774b3b7f5ceba1d47fac95f540f82ec.png)](http://figurepool.com/figure/view/Light_switch_statechart-7774b3b7f5ceba1d47fac95f540f82ec.html)\n\n    var lightSwitch = _.extend({\n        \n        initialState: \"Out\",\n        states: {\n            'Out': {\n                'on':  { target: 'On'   },\n                'out': { target: 'Out'  }\n            },\n            'On': {\n                'on':  { target: 'On'  },\n                'out': { target: 'Out' }\n            }\n        }\n        \n    }, Statechart);\n\n    \n    // Initialize the state machine and make the initial transition (to the `Out` state).\n    lightSwitch.run();\n\n    // Dispatch the `on` event to the machine which causes it to transit to the `On` state.\n    lightSwitch.dispatch('on');\n\n\nReserved events\n---------------\n\nThe state machine dispatched three reserved events: `init`, `entry` and `exit`. These are special\nevents that you might react on when an initial transition to a state takes place, when a state is entered or exited.\n\nAssume we use the same machine as defined in the above example and run it like this:\n\n    lightSwtich.run();\n    lightSwitch.dispatch('out');\n    lightSwitch.dispatch('on');\n\nThe resulting order of transitions would then be:\n\n* [Out] entry\n* [Out] init\n* ... now the `out` event was dispatched\n* [Out] exit\n* [Out] entry\n* [Out] init\n* ... now the `on` event was dispatched\n* [Out] exit\n* [On] entry\n* [On] init\n\n\nCustom events\n-------------\n\nCustom events are named events that we dispatch to the machine (like the `on` and `out` events in the above example).\nAs a reaction on these events, we might want to either transit to another state, execute an action while doing that or\nguard the transition if there is a certain condition that must be met in order for the transition to take place.\n\n    'MyState': {\n        'myEvent': {\n            guard: function() { return this.mySlot === true; },\n            action: function() { console.log('Hooray, transition takes place.'),\n            target: 'AnotherState'\n        }\n    },\n    'AnotherState': {\n    }\n\n\nHierarchical states\n-------------------\n\nStates can be nested to an arbitrary level. State nesting leads to **behavioral inheritance** [Samek+ 00, 02].\nThis allows new states to be specified **by difference** rather then created from scratch each time.\n\n[![Hierarchical states](http://figurepool.com/figure/view/7774b3b7f5ceba1d47fac95f540f86e1.png)](http://figurepool.com/figure/view/Hierarchical_states-7774b3b7f5ceba1d47fac95f540f86e1.html)\n\nState nesting can simply be done by nesting objects.\n\n    'MyState': {\n        'init': 'MyChildState',\n        'eventA': { ... },\n        'MyChildState': {\n            'entry': function() { console.log('MyChildState being entered.'); },\n            'eventB': { ... }\n        }\n    }\n\n\nSee https://github.com/DavidDurman/statechart/blob/master/test/samek.js for a complete example of a non-trivial\nstate machine.\n\n\nCopyright and license\n---------------------\n\nCopyright (c) 2010 David Durman\n\nLicensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at \nhttp://opensource.org/licenses/MIT.\n","readmeFilename":"README.md","_id":"statechart@0.1.1","dist":{"shasum":"9b0c6cee09228e22680b45fa5f26a2950d9c4ef2","tarball":"https://registry.npmjs.org/statechart/-/statechart-0.1.1.tgz","integrity":"sha512-J5yC0MxhidgA1y79ZGTr0PvOLBcwT1ZJ2VaiokARshdvz2hX1/omIWsYwLL7AGQZEQE68nDoda7batAeRtK5Rw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBZCr7AWr+xR8EiTcAtqNaAjLUWarII539HpyJWCBe6dAiBszo2ce0B4Ha/TAaG2JvUOws7ZtLZm3kHwSwNxTXxPSw=="}]},"_from":".","_npmVersion":"1.3.21","_npmUser":{"name":"daviddurman","email":"daviddurman@gmail.com"},"maintainers":[{"name":"daviddurman","email":"daviddurman@gmail.com"}]}},"maintainers":[{"email":"zbynek.stara.internet@hotmail.com","name":"zbynekstara"},{"email":"martin@client.io","name":"martin"},{"email":"daviddurman@gmail.com","name":"daviddurman"},{"email":"bruckner.roman@gmail.com","name":"kumilingus"}],"repository":{"type":"git","url":"git://github.com/DavidDurman/statechart.git"},"time":{"modified":"2022-12-08T10:39:35.415Z","created":"2014-01-11T19:13:55.405Z","0.1.0":"2014-01-11T19:13:55.405Z","0.1.1":"2014-01-13T12:39:44.074Z"},"readme":"Statechart implementation in JavaScript.\n========================================\n\n[![Build Status](https://travis-ci.org/DavidDurman/statechart.png?branch=master)](http://travis-ci.org/DavidDurman/statechart)\n\nFeatures\n--------\n\n * Hierarchical states\n * Can be mixined with an arbitrary object\n * JSON-like description of the machine\n * Fast\n * Lightweight (4.6KB minified using jsmin)\n * JavaScript engine independent (browsers, nodejs, narwhal, ...)\n\nRelated work\n------------\n\nThis hierarchical state machine implementation has been inspired\nby the QP active object framework, see http://www.state-machine.com/.\n\nDefining a basic state machine\n-------------------------------\n\nState machine is defined as an object with `initialState` and `states` properties. The former defines\nthe first state we want our machine to enter. The latter is an object with states, events and actions:\n\n[![Light switch statechart](http://figurepool.com/figure/view/7774b3b7f5ceba1d47fac95f540f82ec.png)](http://figurepool.com/figure/view/Light_switch_statechart-7774b3b7f5ceba1d47fac95f540f82ec.html)\n\n    var lightSwitch = _.extend({\n        \n        initialState: \"Out\",\n        states: {\n            'Out': {\n                'on':  { target: 'On'   },\n                'out': { target: 'Out'  }\n            },\n            'On': {\n                'on':  { target: 'On'  },\n                'out': { target: 'Out' }\n            }\n        }\n        \n    }, Statechart);\n\n    \n    // Initialize the state machine and make the initial transition (to the `Out` state).\n    lightSwitch.run();\n\n    // Dispatch the `on` event to the machine which causes it to transit to the `On` state.\n    lightSwitch.dispatch('on');\n\n\nReserved events\n---------------\n\nThe state machine dispatched three reserved events: `init`, `entry` and `exit`. These are special\nevents that you might react on when an initial transition to a state takes place, when a state is entered or exited.\n\nAssume we use the same machine as defined in the above example and run it like this:\n\n    lightSwtich.run();\n    lightSwitch.dispatch('out');\n    lightSwitch.dispatch('on');\n\nThe resulting order of transitions would then be:\n\n* [Out] entry\n* [Out] init\n* ... now the `out` event was dispatched\n* [Out] exit\n* [Out] entry\n* [Out] init\n* ... now the `on` event was dispatched\n* [Out] exit\n* [On] entry\n* [On] init\n\n\nCustom events\n-------------\n\nCustom events are named events that we dispatch to the machine (like the `on` and `out` events in the above example).\nAs a reaction on these events, we might want to either transit to another state, execute an action while doing that or\nguard the transition if there is a certain condition that must be met in order for the transition to take place.\n\n    'MyState': {\n        'myEvent': {\n            guard: function() { return this.mySlot === true; },\n            action: function() { console.log('Hooray, transition takes place.'),\n            target: 'AnotherState'\n        }\n    },\n    'AnotherState': {\n    }\n\n\nHierarchical states\n-------------------\n\nStates can be nested to an arbitrary level. State nesting leads to **behavioral inheritance** [Samek+ 00, 02].\nThis allows new states to be specified **by difference** rather then created from scratch each time.\n\n[![Hierarchical states](http://figurepool.com/figure/view/7774b3b7f5ceba1d47fac95f540f86e1.png)](http://figurepool.com/figure/view/Hierarchical_states-7774b3b7f5ceba1d47fac95f540f86e1.html)\n\nState nesting can simply be done by nesting objects.\n\n    'MyState': {\n        'init': 'MyChildState',\n        'eventA': { ... },\n        'MyChildState': {\n            'entry': function() { console.log('MyChildState being entered.'); },\n            'eventB': { ... }\n        }\n    }\n\n\nSee https://github.com/DavidDurman/statechart/blob/master/test/samek.js for a complete example of a non-trivial\nstate machine.\n\n\nCopyright and license\n---------------------\n\nCopyright (c) 2010 David Durman\n\nLicensed under the MIT License (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at \nhttp://opensource.org/licenses/MIT.\n"}