-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.html
224 lines (164 loc) · 16.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JSSM</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description" content="jssmA Javascript state machine with a simple API. Well tested, and typed with Flowtype. MIT license. TL;DRSpecify finite state machines with a brief syntax. Run them. Derive charts from them. S">
<meta property="og:type" content="article">
<meta property="og:title" content="JSSM">
<meta property="og:url" content="http://yoursite.com/jssm/2017/05/28/index/index.html">
<meta property="og:site_name" content="JSSM">
<meta property="og:description" content="jssmA Javascript state machine with a simple API. Well tested, and typed with Flowtype. MIT license. TL;DRSpecify finite state machines with a brief syntax. Run them. Derive charts from them. S">
<meta property="og:image" content="https://img.shields.io/npm/l/jssm.svg">
<meta property="og:image" content="https://img.shields.io/github/issues/StoneCypher/jssm.svg">
<meta property="og:image" content="https://img.shields.io/github/issues-closed/StoneCypher/jssm.svg">
<meta property="og:image" content="https://david-dm.org/StoneCypher/jssm/status.svg">
<meta property="og:image" content="https://nodesecurity.io/orgs/johns-oss/projects/f479470f-fc0a-4e7e-a250-d69cb3778601/badge">
<meta property="og:image" content="https://img.shields.io/travis/StoneCypher/jssm.svg">
<meta property="og:image" content="https://img.shields.io/coveralls/StoneCypher/jssm.svg">
<meta property="og:image" content="https://img.shields.io/codeclimate/github/StoneCypher/jssm.svg">
<meta property="og:image" content="https://img.shields.io/npm/v/jssm.svg">
<meta property="og:image" content="https://img.shields.io/cdnjs/v/jquery.svg">
<meta property="og:image" content="https://img.shields.io/npm/dt/jssm.svg">
<meta property="og:image" content="https://img.shields.io/github/commits-since/StoneCypher/jssm/0.0.0.svg">
<meta property="og:image" content="http://yoursite.com/jssm/2017/05/28/index/docs/ryg%20traffic%20light%20console%20screenshot.png">
<meta property="og:updated_time" content="2017-05-28T09:36:21.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="JSSM">
<meta name="twitter:description" content="jssmA Javascript state machine with a simple API. Well tested, and typed with Flowtype. MIT license. TL;DRSpecify finite state machines with a brief syntax. Run them. Derive charts from them. S">
<meta name="twitter:image" content="https://img.shields.io/npm/l/jssm.svg">
<link rel="alternate" href="/atom.xml" title="JSSM" type="application/atom+xml">
<link rel="icon" href="/favicon.png">
<link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="/jssm/css/style.css">
</head>
<body>
<div id="container">
<div id="wrap">
<header id="header">
<div id="banner"></div>
<div id="header-outer" class="outer">
<div id="header-title" class="inner">
<h1 id="logo-wrap">
<a href="/jssm/" id="logo">JSSM</a>
</h1>
<h2 id="subtitle-wrap">
<a href="/jssm/" id="subtitle">Javascript State Machine</a>
</h2>
</div>
<div id="header-inner" class="inner">
<nav id="main-nav">
<a id="main-nav-toggle" class="nav-icon"></a>
<a class="main-nav-link" href="/jssm/">Home</a>
<a class="main-nav-link" href="/jssm/archives">Archives</a>
</nav>
<nav id="sub-nav">
<a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
<a id="nav-search-btn" class="nav-icon" title="Search"></a>
</nav>
<div id="search-form-wrap">
<form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit"></button><input type="hidden" name="sitesearch" value="http://yoursite.com/jssm"></form>
</div>
</div>
</div>
</header>
<div class="outer">
<section id="main"><article id="post-index" class="article article-type-post" itemscope itemprop="blogPost">
<div class="article-meta">
<a href="/jssm/2017/05/28/index/" class="article-date">
<time datetime="2017-05-28T09:36:21.000Z" itemprop="datePublished">2017-05-28</time>
</a>
</div>
<div class="article-inner">
<div class="article-entry" itemprop="articleBody">
<h1 id="jssm"><a href="#jssm" class="headerlink" title="jssm"></a>jssm</h1><p>A Javascript state machine with a simple API. Well tested, and typed with Flowtype. MIT license.</p>
<div id="badge_style_hook"><br><br><a href="https://img.shields.io/npm/l/jssm.svg" target="_blank" rel="external"><img src="https://img.shields.io/npm/l/jssm.svg" alt="License"></a><br><a href="https://img.shields.io/github/issues/StoneCypher/jssm.svg" target="_blank" rel="external"><img src="https://img.shields.io/github/issues/StoneCypher/jssm.svg" alt="Open issues"></a><br><a href="https://img.shields.io/github/issues-closed/StoneCypher/jssm.svg" target="_blank" rel="external"><img src="https://img.shields.io/github/issues-closed/StoneCypher/jssm.svg" alt="Closed issues"></a><br><br><a href="https://david-dm.org/StoneCypher/jssm" target="_blank" rel="external"><img src="https://david-dm.org/StoneCypher/jssm/status.svg" alt="Dependency status"></a><br><a href="https://nodesecurity.io/orgs/johns-oss/projects/f479470f-fc0a-4e7e-a250-d69cb3778601" target="_blank" rel="external"><img src="https://nodesecurity.io/orgs/johns-oss/projects/f479470f-fc0a-4e7e-a250-d69cb3778601/badge" alt="NSP status"></a><br><a href="https://img.shields.io/travis/StoneCypher/jssm.svg" target="_blank" rel="external"><img src="https://img.shields.io/travis/StoneCypher/jssm.svg" alt="Travis status"></a><br><a href="https://img.shields.io/coveralls/StoneCypher/jssm.svg" target="_blank" rel="external"><img src="https://img.shields.io/coveralls/StoneCypher/jssm.svg" alt="Coveralls status"></a><br><a href="https://img.shields.io/codeclimate/github/StoneCypher/jssm.svg" target="_blank" rel="external"><img src="https://img.shields.io/codeclimate/github/StoneCypher/jssm.svg" alt="CodeClimate status"></a><br><br><a href="https://img.shields.io/npm/v/jssm.svg" target="_blank" rel="external"><img src="https://img.shields.io/npm/v/jssm.svg" alt="NPM version"></a><br><a href="https://img.shields.io/cdnjs/v/jquery.svg" target="_blank" rel="external"><img src="https://img.shields.io/cdnjs/v/jquery.svg" alt="CDNjs version"></a><br><a href="https://img.shields.io/npm/dt/jssm.svg" target="_blank" rel="external"><img src="https://img.shields.io/npm/dt/jssm.svg" alt="NPM downloads"></a><br><br><a href="https://img.shields.io/github/commits-since/StoneCypher/jssm/0.0.0.svg" target="_blank" rel="external"><img src="https://img.shields.io/github/commits-since/StoneCypher/jssm/0.0.0.svg" alt="Commits since"></a><br><br></div>
<h2 id="TL-DR"><a href="#TL-DR" class="headerlink" title="TL;DR"></a>TL;DR</h2><p>Specify finite state machines with a brief syntax. Run them. Derive charts from them. Save and load states. Make factories. Impress friends and loved ones. Cure corns and callouses.</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">const</span> traffic_light = <span class="keyword">new</span> jssm.machine({</div><div class="line"></div><div class="line"> <span class="attr">initial_state</span> : <span class="string">'Red'</span>,</div><div class="line"></div><div class="line"> <span class="attr">transitions</span> : [</div><div class="line"> { <span class="attr">action</span>: <span class="string">'Proceed'</span>, <span class="attr">from</span>:<span class="string">'Green'</span>, <span class="attr">to</span>:<span class="string">'Yellow'</span> },</div><div class="line"> { <span class="attr">action</span>: <span class="string">'Proceed'</span>, <span class="attr">from</span>:<span class="string">'Yellow'</span>, <span class="attr">to</span>:<span class="string">'Red'</span> },</div><div class="line"> { <span class="attr">action</span>: <span class="string">'Proceed'</span>, <span class="attr">from</span>:<span class="string">'Red'</span>, <span class="attr">to</span>:<span class="string">'Green'</span> }</div><div class="line"> ]</div><div class="line"></div><div class="line">});</div><div class="line"></div><div class="line"><span class="comment">// use with actions</span></div><div class="line">traffic_light.state(); <span class="comment">// 'Red'</span></div><div class="line">traffic_light.action(<span class="string">'Proceed'</span>); <span class="comment">// true</span></div><div class="line">traffic_light.state(); <span class="comment">// 'Green'</span></div><div class="line">traffic_light.action(<span class="string">'Proceed'</span>); <span class="comment">// true</span></div><div class="line">traffic_light.state(); <span class="comment">// 'Yellow'</span></div><div class="line">traffic_light.action(<span class="string">'Proceed'</span>); <span class="comment">// true</span></div><div class="line">traffic_light.state(); <span class="comment">// 'Red'</span></div><div class="line"></div><div class="line"><span class="comment">// use with transitions</span></div><div class="line">traffic_light.transition(<span class="string">'Yellow'</span>); <span class="comment">// false (lights can't go from red to yellow, only to green)</span></div><div class="line">traffic_light.state(); <span class="comment">// 'Red'</span></div><div class="line">traffic_light.transition(<span class="string">'Red'</span>); <span class="comment">// false (lights can't go from red to red, either)</span></div><div class="line">traffic_light.state(); <span class="comment">// 'Red'</span></div><div class="line">traffic_light.transition(<span class="string">'Green'</span>); <span class="comment">// true</span></div><div class="line">traffic_light.state(); <span class="comment">// 'Green'</span></div></pre></td></tr></table></figure>
<p>Which you can see being hand-executed in the console here:</p>
<p><img src="./docs/ryg%20traffic%20light%20console%20screenshot.png" alt=""></p>
<p><br><br></p>
<h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h2 id="Why"><a href="#Why" class="headerlink" title="Why"></a>Why</h2><h2 id="How-To"><a href="#How-To" class="headerlink" title="How To"></a>How To</h2><h2 id="Other-state-machines"><a href="#Other-state-machines" class="headerlink" title="Other state machines"></a>Other state machines</h2><p>There are a lot of state machine impls for JS, many quite a bit more mature than this one. Here are some options:</p>
<ol>
<li><a href="https://github.com/nickuraltsev/finity" target="_blank" rel="external">Finity</a> 😮</li>
<li><a href="https://github.com/fschaefer/Stately.js" target="_blank" rel="external">Stately.js</a></li>
<li><a href="https://github.com/ifandelse/machina.js" target="_blank" rel="external">machina.js</a></li>
<li><a href="https://github.com/orbitbot/pastafarian" target="_blank" rel="external">Pastafarian</a></li>
<li><a href="https://github.com/orbitbot/henderson" target="_blank" rel="external">Henderson</a></li>
<li><a href="https://github.com/vstirbu/fsm-as-promised" target="_blank" rel="external">fsm-as-promised</a></li>
<li><a href="https://github.com/DEADB17/state-machine" target="_blank" rel="external">state-machine</a></li>
<li><a href="https://github.com/bredele/mood" target="_blank" rel="external">mood</a></li>
<li><a href="https://github.com/MatthewHepburn/FSM-Workbench" target="_blank" rel="external">FSM Workbench</a></li>
<li><a href="https://github.com/ccnokes/SimpleStateMachine" target="_blank" rel="external">SimpleStateMachine</a></li>
<li>shime/<a href="https://github.com/shime/micro-machine" target="_blank" rel="external">micro-machine</a><ol>
<li>soveran/<a href="https://github.com/soveran/micromachine" target="_blank" rel="external">micromachine</a> (ruby)</li>
</ol>
</li>
<li>fabiospampinato/<a href="https://github.com/fabiospampinato/FSM" target="_blank" rel="external">FSM</a></li>
<li>HQarroum/<a href="https://github.com/HQarroum/Fsm" target="_blank" rel="external">FSM</a></li>
<li><a href="https://github.com/RolandR/Finite-State-Automata" target="_blank" rel="external">Finite-State-Automata</a></li>
<li><a href="https://github.com/MarkH817/finite-state-machine" target="_blank" rel="external">finite-state-machine</a></li>
<li><a href="https://github.com/ajauhri/nfm" target="_blank" rel="external">nfm</a></li>
</ol>
<p>And some similar stuff:</p>
<ol>
<li><a href="https://github.com/mheiber/redux-machine" target="_blank" rel="external">redux-machine</a></li>
<li><a href="https://github.com/heycarsten/ember-fsm" target="_blank" rel="external">ember-fsm</a></li>
<li><a href="https://github.com/sverweij/state-machine-cat" target="_blank" rel="external">State machine cat</a></li>
<li><a href="https://github.com/AlexLevshin/workty" target="_blank" rel="external">Workty</a> 😮</li>
<li><a href="https://github.com/sladiri/sam-simpler" target="_blank" rel="external">sam-simpler</a></li>
<li><a href="https://github.com/quilin/event_chain" target="_blank" rel="external">event_chain</a></li>
<li><a href="https://en.wikipedia.org/wiki/DRAKON" target="_blank" rel="external">DRAKON</a></li>
<li><a href="https://github.com/Yakindu/statecharts" target="_blank" rel="external">Yakindu Statechart Tools</a></li>
<li><a href="http://www.graphviz.org/" target="_blank" rel="external">GraphViz</a><ol>
<li><a href="https://github.com/mdaines/viz.js/" target="_blank" rel="external">Viz.js</a>, which we use</li>
</ol>
</li>
</ol>
</div>
<footer class="article-footer">
<a data-url="http://yoursite.com/jssm/2017/05/28/index/" data-id="cj38gwcpp0000y2iu3llxfuta" class="article-share-link">Share</a>
</footer>
</div>
</article>
</section>
<aside id="sidebar">
<div class="widget-wrap">
<h3 class="widget-title">Archives</h3>
<div class="widget">
<ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/jssm/archives/2017/05/">May 2017</a></li></ul>
</div>
</div>
<div class="widget-wrap">
<h3 class="widget-title">Recent Posts</h3>
<div class="widget">
<ul>
<li>
<a href="/jssm/2017/05/28/index/">(no title)</a>
</li>
</ul>
</div>
</div>
</aside>
</div>
<footer id="footer">
<div class="outer">
<div id="footer-info" class="inner">
JSSM © 2017 John Haugeland
- <a target="_blank" href="https://github.com/StoneCypher/jssm">Github</a>
- <a target="_blank" href="https://www.npmjs.com/package/jssm">NPM</a>
- <a target="_blank" href="https://github.com/StoneCypher/jssm/blob/master/LICENSE.md">MIT License</a>
</div>
</div>
</footer>
</div>
<nav id="mobile-nav">
<a href="/jssm/" class="mobile-nav-link">Home</a>
<a href="/jssm/archives" class="mobile-nav-link">Archives</a>
</nav>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="/jssm/js/script.js"></script>
</div>
</body>
</html>