{"_id":"stately","_rev":"12-ced08ec39b3abf9b1aaa57a12e77973d","name":"stately","description":"A CommonJS state-machine that works in Node or the browser","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.1":{"name":"stately","description":"A CommonJS state-machine that works in Node or the browser","homepage":"http://github.com/jchris/stately","version":"0.1.1","author":{"name":"J Chris Anderson","email":"jchris@couch.io","url":"http://jchrisa.net"},"contributors":[],"repository":{"type":"git","url":"http://github.com/jchris/stately.git"},"bugs":{"mail":"jchris@couch.io","web":"http://github.com/jchris/stately/issues"},"directories":{"lib":"./lib"},"engines":{"node":">=0.2.0"},"licenses":[{"type":"Apache 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0.html"}],"main":"./lib/stately","dependencies":{"vows":">=0.5.1"},"_id":"stately@0.1.1","_nodeSupported":true,"_npmVersion":"0.2.7-2","_nodeVersion":"v0.3.1-pre","dist":{"tarball":"https://registry.npmjs.org/stately/-/stately-0.1.1.tgz","shasum":"ce7f56b2a8b5f21bc69f6e84cef0fedf55a7698a","integrity":"sha512-Si/gXR/1v4hDubtdIYoy/7VmBSHp+B5jlqGzTh60PqF+0NO/sF65wtNPU7TmrR9eCmQH6SqVI8XlPc7IFHLbuQ==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIA5xQZ7Tu2ijVM0xgXCNm9GnAR+SUdOpO/jmpc4vr77kAiBCkOPyt3UVJCeKsXItNJC8beKNsZwULmXAXwXm/d/W+Q=="}]}},"0.1.2":{"name":"stately","description":"A CommonJS state-machine that works in Node or the browser","homepage":"http://github.com/jchris/stately","version":"0.1.2","author":{"name":"J Chris Anderson","email":"jchris@couchbase.com","url":"http://jchrisa.net"},"contributors":[],"repository":{"type":"git","url":"git://github.com/jchris/stately.git"},"bugs":{"email":"jchris@couchbase.com","url":"http://github.com/jchris/stately/issues"},"directories":{"lib":"./lib"},"engines":{"node":">=0.2.0"},"licenses":[{"type":"Apache 2.0","url":"http://www.apache.org/licenses/LICENSE-2.0.html"}],"main":"./lib/stately","devDependencies":{"vows":">=0.5.1"},"_npmUser":{"name":"jchris","email":"jchris@couchbase.com"},"_id":"stately@0.1.2","dependencies":{},"optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.0-3","_nodeVersion":"v0.6.10","_defaultsLoaded":true,"dist":{"shasum":"5a14afbff600d12672ab2effad949927c893cdb4","tarball":"https://registry.npmjs.org/stately/-/stately-0.1.2.tgz","integrity":"sha512-D5uzoCXEqp4nY1441h25DJK4r4atp3cCNglPzTtqjrL+5s3p/BpsGMnIOoiIHx9khKs/kg55AcMUTDIx103xrw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDeLwos0CLT71YOh7xHZ0HnwbLJtcPpVhiiAX9u2Bnb0wIhAM+J5tmvxQX/HMkj976ZOAE7NV9hSSW+QrNG+MhZjdVg"}]},"maintainers":[{"name":"jchris","email":"jchris@couch.io"}]}},"maintainers":[{"name":"jchris","email":"jchris@couch.io"}],"author":{"name":"J Chris Anderson","email":"jchris@couchbase.com","url":"http://jchrisa.net"},"repository":{"type":"git","url":"git://github.com/jchris/stately.git"},"time":{"0.1.2":"2012-04-16T16:49:08.289Z","modified":"2022-06-27T00:00:49.324Z","created":"2012-04-16T16:49:08.289Z","0.1.1":"2012-04-16T16:49:08.289Z"},"readme":"# Stately\n## A CommonJS state-machine that works in Node or the browser.\n\nThis is extracted from [Twebz](http://github.com/jchris/twebz) and is designed to DRY out [the CouchDB changes listner Twebz's bot uses for handling Twitter API interactions](http://github.com/jchris/twebz/commit/4a23d999763dda0bcd9305833346aefd7a31d376). That said, this is entirely agnostic to backends and should work great with Redis, message queues, or anything else where you can get a feed of updates as they are happening to the database.\n\nIt is totally isolated from IO, so it will also run fine in the browser, although I haven't done that yet.\n\n## Usage\n\n    var stately = require(\"stately\")\n      , myMachine = stately.define({\n        foo : function(obj) {\n          // this function will be called if obj.state == \"foo\"\n          obj.fooRan = true;\n        }\n      })\n      , obj = {state : \"foo\", fooRan : false};\n\n    myMachine.handle(obj);\n    \n    assert.isTrue(obj.fooRan);\n\nIn real life you would hook `myMachine.handle` up as the listener to events on a Node.js stream. Or in the browser as the callback to an event system or a comet feed.\n\nYou can also deal with objects of multiple types if you want, by nesting the definitions one-layer deep, see the tests for details.\n\nThe `_getState` and `_getType` methods are pluggable.\n\n## Tests\n\nHaters gonna hate, but I used [Vows](http://vowsjs.org) and \"it works!\"\n\nTo run them:\n\n    npm install vows\n    vows test/test.js\n\n## TODO\n\n* Test modifying the states after definition\n* Document more usage scenarios\n\n## License\n\n[Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0.html)\n","readmeFilename":""}