1- Javascript Finite State Machine (v2.4.0)
2- ========================================
1+ # Javascript Finite State Machine (v2.4.0)
32
43This standalone javascript micro-framework provides a finite state machine for your pleasure.
54
65 * You can find the [ code here] ( https://github.com/jakesgordon/javascript-state-machine )
76 * You can find a [ description here] ( http://codeincomplete.com/posts/2013/1/26/javascript_state_machine_v2_2_0/ )
87 * You can find a [ working demo here] ( http://codeincomplete.com/posts/2011/8/19/javascript_state_machine_v2/example/ )
98
10- Download
11- ========
9+ # Download
1210
1311Using npm:
1412
15- npm install --save javascript-state-machine
13+ npm install javascript-state-machine
1614
1715Or download the source from [ state-machine.js] ( https://github.com/jakesgordon/javascript-state-machine/raw/master/state-machine.js ) ,
1816or the [ minified version] ( https://github.com/jakesgordon/javascript-state-machine/raw/master/state-machine.min.js )
1917
20- Alternatively:
18+ # Usage
2119
22- git clone git@github.com:jakesgordon/javascript-state-machine
23-
24-
25- * All code is in state-machine.js
26- * Minified version provided in state-machine.min.js
27- * No 3rd party library is required
28- * Demo can be found in /index.html
29- * QUnit (browser) tests can be found in /test/index.html
30- * QUnit (headless) tests can be run with "npm run test" (after "npm install")
31-
32- Usage
33- =====
34-
35- Include ` state-machine.js ` in your web application, or, for npm ` require("javascript-state-machine") ` .
20+ Include ` state-machine.js ` in your web application, or, for npm ` require('javascript-state-machine') ` .
3621
3722In its simplest form, create a standalone state machine using:
3823
@@ -60,8 +45,7 @@ along with the following members:
6045 * fsm.cannot(e) - return true if event ` e ` cannot be fired in the current state
6146 * fsm.transitions() - return list of events that are allowed from the current state
6247
63- Multiple 'from' and 'to' states for a single event
64- ==================================================
48+ # Multiple 'from' and 'to' states for a single event
6549
6650If an event is allowed ** from** multiple states, and always transitions to the same
6751state, then simply provide an array of states in the ` from ` attribute of an event. However,
@@ -92,8 +76,7 @@ allowed from any current state.
9276>> NOTE: The ` rest ` event in the above example can also be specified as multiple events with
9377 the same name if you prefer the verbose approach.
9478
95- Callbacks
96- =========
79+ # Callbacks
9780
98814 types of callback are available by attaching methods to your StateMachine using the following naming conventions:
9982
@@ -175,8 +158,7 @@ You can affect the event in 3 ways:
175158 * return ` false ` from an ` onleaveSTATE ` handler to cancel the event.
176159 * return ` ASYNC ` from an ` onleaveSTATE ` handler to perform an asynchronous state transition (see next section)
177160
178- Asynchronous State Transitions
179- ==============================
161+ # Asynchronous State Transitions
180162
181163Sometimes, you need to execute some asynchronous code during a state transition and ensure the
182164new state is not entered until your code has completed.
@@ -224,8 +206,7 @@ For example, using jQuery effects:
224206
225207>> _ NOTE: If you decide to cancel the ASYNC event, you can call ` fsm.transition.cancel(); `
226208
227- State Machine Classes
228- =====================
209+ # State Machine Classes
229210
230211You can also turn all instances of a _ class_ into an FSM by applying
231212the state machine functionality to the prototype, including your callbacks
@@ -261,8 +242,7 @@ This should be easy to adjust to fit your appropriate mechanism for object const
261242>> _ NOTE: the ` startup ` event can be given any name, but it must be present in some form to
262243 ensure that each instance constructed is initialized with its own unique ` current ` state._
263244
264- Initialization Options
265- ======================
245+ # Initialization Options
266246
267247How the state machine should initialize can depend on your application requirements, so
268248the library provides a number of simple options.
@@ -325,8 +305,7 @@ So you have a number of choices available to you when initializing your state ma
325305 that each instance gets its own unique ` current ` state, rather than an (unwanted) shared
326306 ` current ` state on the prototype object itself._
327307
328- Handling Failures
329- ======================
308+ # Handling Failures
330309
331310By default, if you try to call an event method that is not allowed in the current state, the
332311state machine will throw an exception. If you prefer to handle the problem yourself, you can
@@ -343,20 +322,31 @@ define a custom `error` handler:
343322 ]});
344323 alert(fsm.calm()); // "event calm was naughty :- event not allowed in current state green"
345324
346- Release Notes
347- =============
325+ # Contributing
326+
327+ > git clone git@github.com:jakesgordon/javascript-state-machine
328+ > cd javascript-state-machine
329+
330+ > npm install # install dev dependencies
331+ > npm start # run a local dev server
332+
333+ * Source code - ` state-machine.js `
334+ * Minified code - ` state-machine.min.js ` (build with ` npm run minify ` )
335+ * Browse demo at ` / `
336+ * Run tests in browser at ` /test/ `
337+ * Run tests in console with ` npm test `
338+ * Please include tests with pull requests.
339+
340+ # Release Notes
348341
349342See [ RELEASE NOTES] ( https://github.com/jakesgordon/javascript-state-machine/blob/master/RELEASE_NOTES.md ) file.
350343
351- License
352- =======
344+ # License
353345
354346See [ LICENSE] ( https://github.com/jakesgordon/javascript-state-machine/blob/master/LICENSE ) file.
355347
356- Contact
357- =======
348+ # Contact
358349
359350If you have any ideas, feedback, requests or bug reports, you can reach me at
360351[ jake@codeincomplete.com ] ( mailto:jake@codeincomplete.com ) , or via
361352my website: [ Code inComplete] ( http://codeincomplete.com/ )
362-
0 commit comments