-
-
Save DmitryMyadzelets/c4619f96fb29e5b4a22f to your computer and use it in GitHub Desktop.
Revisions
-
podefr revised this gist
Mar 29, 2012 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,4 +15,6 @@ v2: 128 bytes and the actions can be executed in a given context v3: 126 bytes with careful reuse of an already declared var -c- in the event function v4: 125 bytes by using the assignment c=b[a][c] directly to determine whether or not the event exists v5: 106 bytes by removing unecessary code! What feature should I add now? -
podefr revised this gist
Mar 29, 2012 . 2 changed files with 12 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,20 +13,20 @@ * @returns {Object} */ SM = function( a // stores the current state ,b // an object to store all states and their transitions ){ return{ event:function( // The function to send an event to the state machine c // The name of the event ,d // The arguments to pass to the action ){ return (c=b[a][c]) // Save the array [action, nextState] in c which is carefuly reused, && ( // If c is defined. (c[0][0]||c[0]) // Either c[0] is the function, or c[0][0] if a scope is given .call(c[0][1],d), // call the function in the context or call it directly a=c[1]||a // The next state is the new state and the new state is returned ) } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ function(a,b){return{event:function(c,d){return(c=b[a][c])&&((c[0][0]||c[0]).call(c[0][1],d),a=c[1]||a)}}} -
podefr revised this gist
Mar 29, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ * @param {String} a the state on which the state machine will be initialized * @param {Object} b the state machine's diagram : * { "state1": { * "event1": [action1, "state2"], * "event2": [action2] * }, * "state2": { -
podefr revised this gist
Oct 31, 2011 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,12 @@ Finite State Machine ========= Generates a state machine with the value you pass in parameter. You can define states, transitions to these states, pass parameters to the actions, and execute the actions in a given context. This code was test driven developed with JsTestDriver, the TestCase is attached. Downsized with the help of UglifyJS on marijn's website : http://marijnhaverbeke.nl/uglifyjs The example of the state machine comes from http://www.objectmentor.com/resources/articles/umlfsm.pdf v1: only 85 bytes but the actions were ran in the global scope -
podefr revised this gist
Oct 28, 2011 . 3 changed files with 14 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,4 +12,6 @@ v1: only 85 bytes but the actions were ran in the global scope v2: 128 bytes and the actions can be executed in a given context v3: 126 bytes with careful reuse of an already declared var -c- in the event function v4: 125 bytes by using the assignment c=b[a][c] directly to determine whether or not the event exists This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,20 +13,20 @@ * @returns {Object} */ SM = function( a // stores the current state ,b // an object to store all states and their transitions ){ return{ event:function( // The function to send an event to the state machine c // The name of the event ,d // The arguments to pass to the action ,e ,f ){ return (c=b[a][c]) // Save the array [action, nextState] in c which is carefuly reused, &&(e=c[0],f=e[0], // And if c is defined. f&&f.call?f.call(e[1],d):e(d), // call the function with the context or call it directly a=c[1]||a) // The next state is the new state and the new state is returned } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ function(a,b){return{event:function(c,d,e,f){return(c=b[a][c])&&(e=c[0],f=e[0],f&&f.call?f.call(e[1],d):e(d),a=c[1]||a)}}} -
podefr revised this gist
Oct 28, 2011 . 2 changed files with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,14 +19,14 @@ SM = function( return{ event:function( // The function to send an event to the state machine c // The name of the event ,d // The arguments to pass to the action ,e ,f ){ c=b[a][c] // Save the array [action, nextState] in c which is carefuly reused return c&&(e=c[0],f=e[0], // If c is defined. f&&f.call?f.call(e[1],d):e(d), // call the function with the context or call it directly a=c[1]||a) // The next state is the new state and the new state is returned } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ SM=function(a,b){return{event:function(c,d,e,f){return c=b[a][c],c&&(e=c[0],f=e[0],f&&f.call?f.call(e[1],d):e(d),a=c[1]||a)}}} -
podefr revised this gist
Oct 28, 2011 . 3 changed files with 7 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,4 +10,6 @@ The example of the state machine comes from http://www.objectmentor.com/resource v1: only 85 bytes but the actions were ran in the global scope v2: 128 bytes and the actions can be executed in a given context v3: 126 bytes with careful reuse of an already declared var -c- in the event function This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,11 +21,11 @@ SM = function( c // The name of the event ,d // The arguments to pass to the action ,e ,f ){ e=b[a][c] // Save the array [action, nextState] in e return e&&(f=e[0],c=f[0], // If e is defined, careful reuse of c to save 2 bytes c&&c.call?c.call(f[1],d):f(d), // if call the function with the context or call it directly a=e[1]||a) // The next state is the new state and the new state is returned } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ function(a,b){return{event:function(c,d,e,f){return e=b[a][c],e&&(f=e[0],c=f[0],c&&c.call?c.call(f[1],d):f(d),a=e[1]||a)}}} -
podefr revised this gist
Oct 28, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,8 +6,8 @@ You can define states, transitions to these states, parameters to the actions, a This code was test driven developed with JsTestDriver, the TestCase is attached Downsized with the help of UglifyJS on marijn's website : http://marijnhaverbeke.nl/uglifyjs The example of the state machine comes from http://www.objectmentor.com/resources/articles/umlfsm.pdf v1: only 85 bytes but the actions were ran in the global scope v2: 128 bytes and the actions can be executed in a given context -
podefr revised this gist
Oct 27, 2011 . 2 changed files with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,10 +23,10 @@ SM = function( ,e ,f ){ e=b[a][c] // Save the array [action, nextState] in e return e&&(f=e[0], // If e is defined f[0]&&f[0].call?f[0].call(f[1],d):f(d), // if call the function with the context or call it directly a=e[1]||a) // The next state is the new state and the new state is returned } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ function(a,b){return{event:function(c,d,e,f){return e=b[a][c],e&&(f=e[0],f[0]&&f[0].call?f[0].call(f[1],d):f(d),a=e[1]||a)}}} -
podefr revised this gist
Oct 27, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ /** * Create a finite state machine * @param {String} a the state on which the state machine will be initialized * @param {Object} b the state machine's diagram : * { "state1": { * "event1": [action1, state2], * "event2": [action2] -
podefr revised this gist
Oct 27, 2011 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,4 +9,5 @@ Downsized with the help of UglifyJS on marijn's website : http://marijnhaverbeke The example of the state machine comes from ... (need to find the url) v1: only 85 bytes but the actions were ran in the global scope v2: 128 bytes but the actions can be executed in a given context -
podefr revised this gist
Oct 27, 2011 . 5 changed files with 47 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2011 Olivier Scherrer Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,10 +2,11 @@ State Machine Generator ========= Generates a state machine with the value you pass in parameter You can define states, transitions to these states, parameters to the actions, and execute the actions in a given context. This code was test driven developed with JsTestDriver, the TestCase is attached Downsized with the help of UglifyJS on marijn's website : http://marijnhaverbeke.nl/uglifyjs The example of the state machine comes from ... (need to find the url) v1: only 85 bytes but the actions were ran in the global scope v2: 128 bytes but the actions can be executed in a given context This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,32 @@ /** * Create a finite state machine * @param {String} a the state on which the state machine will be initialized * @param {Object} the state machine's diagram : * { "state1": { * "event1": [action1, state2], * "event2": [action2] * }, * "state2": { * "event3": [[action3, context], "state1"] * } * } * @returns {Object} */ SM = function( a // stores the current state ,b // an object to store all states and their transitions ){ return{ event:function( // The function to send an event to the state machine c // The name of the event ,d // The arguments to pass to the action ,e ,f ){ e=b[a][c]; // Save the array [action, nextState] in e if(e)return f=e[0], // If e is defined f[0]&&f[0].call?f[0].call(f[1],d):f(d), // if call the function with the context or call it directly a=e[1]||a // The next state is the new state and the new state is returned } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ function(a,b){return{event:function(c,d,e,f){e=b[a][c];if(e)return f=e[0],f[0]&&f[0].call?f[0].call(f[1],d):f(d),a=e[1]||a}}} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ TestCase("SM", { "test SM API": function() { var sm = SM(); assertFunction(sm.event); }, "test SM transits between 2 states": function() { @@ -17,11 +17,11 @@ TestCase("SM", { }); assertUndefined(open.called); assertEquals("opened", sm.event("open!")); assertTrue(open.called); assertUndefined(close.called); assertEquals("closed", sm.event("close!")); assertTrue(close.called); }, @@ -30,7 +30,7 @@ TestCase("SM", { var sm = SM("state", { "state": {"event": [function(){}, "nextState"]} }); assertUndefined(sm.event("crash!")); }, "test SM can pass arguments to the action": function () { @@ -42,11 +42,22 @@ TestCase("SM", { arg = {}, arg2 = {}; sm.event("event", arg); assertSame(arg, action.arg); sm.event("event", arg2); assertSame(arg2, action.arg); }, "test SM can run actions in given context": function () { var action = function() { action.ctx = this; }, ctx = {}, sm = SM("state", { "state": { "event": [[action, ctx], "nextState"]}}); sm.event("event"); assertSame(ctx, action.ctx); }, "test the whole diagram": function() { @@ -66,19 +77,19 @@ TestCase("SM", { } }); assertEquals("closed", sm.event("pass", "picture")); assertTrue(alarm.called); assertEquals("picture", alarm.args[0]); assertEquals("opened", sm.event("coin", "$2")); assertTrue(open.called); assertEquals("$2", open.args[0]); assertEquals("opened", sm.event("coin", "c50")); assertTrue(thank.called); assertEquals("c50", thank.args[0]); assertEquals("closed", sm.event("pass")); assertTrue(close.called); } -
podefr revised this gist
Oct 25, 2011 . 5 changed files with 72 additions and 56 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2011 Olivier Scherrer <YOUR_URL_HERE> Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,11 @@ State Machine Generator ========= Generates a state machine with the value you pass in parameter You can define states, transitions to these states, and parameters to the actions This code was test driven developed with JsTestDriver, the TestCase is attached Downsized with the help of UglifyJS on marijn's website : http://marijnhaverbeke.nl/uglifyjs The example of the state machine comes from ... (need to find the url) As it's only 85 bytes, I could try to pass a context to execute the action in. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,23 +2,14 @@ SM = function( a // stores the current state ,b // an object to store all states and their transitions ){ return{ ev:function( // The function to send an event to the state machine c // The name of the event ,d // The arguments to pass to the action ,e ){ return e=b[a][c], // Save the array [action, nextState] in e e&&(e[0](d),a=e[1]||a) // If e is defined, execute the action, then assign the nextState to current and return it } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ function(a,b){return{ev:function(c,d,e){return e=b[a][c],e&&(e[0](d),a=e[1]||a)}}} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,61 +1,83 @@ TestCase("SM", { "test SM API": function() { var sm = SM(); assertFunction(sm.ev); }, "test SM transits between 2 states": function() { var open=function(){open.called=true;}, close=function(){close.called=true;}, sm = SM("closed", { // When in closed state, if the event is "open!" then execute the open action and go to opened state. "closed":{"open!": [open, "opened"]}, // The opposite "opened":{ "close!": [close, "closed"]} }); assertUndefined(open.called); assertEquals("opened", sm.ev("open!")); assertTrue(open.called); assertUndefined(close.called); assertEquals("closed", sm.ev("close!")); assertTrue(close.called); }, "test SM doesn't crash if wrong event in given state": function() { var sm = SM("state", { "state": {"event": [function(){}, "nextState"]} }); assertUndefined(sm.ev("crash!")); }, "test SM can pass arguments to the action": function () { var action = function(arg) {action.arg = arg; }, sm = SM("state", { "state": {"event": [action, "state2"]}, "state2": {"event": [action]} }), arg = {}, arg2 = {}; sm.ev("event", arg); assertSame(arg, action.arg); sm.ev("event", arg2); assertSame(arg2, action.arg); }, "test the whole diagram": function() { var alarm = function () { alarm.called = true; alarm.args = arguments; }, open = function () { open.called = true; open.args = arguments; }, thank = function () { thank.called = true; thank.args = arguments; }, close = function () { close.called = true; close.args = arguments; }, sm = SM("closed", { "closed": { "pass": [alarm], "coin": [open, "opened"] }, "opened": { "coin": [thank], "pass": [close, "closed"] } }); assertEquals("closed", sm.ev("pass", "picture")); assertTrue(alarm.called); assertEquals("picture", alarm.args[0]); assertEquals("opened", sm.ev("coin", "$2")); assertTrue(open.called); assertEquals("$2", open.args[0]); assertEquals("opened", sm.ev("coin", "c50")); assertTrue(thank.called); assertEquals("c50", thank.args[0]); assertEquals("closed", sm.ev("pass")); assertTrue(close.called); -
podefr revised this gist
Oct 25, 2011 . 2 changed files with 17 additions and 41 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,32 +1,8 @@ State Machine Generator ========= Generates a state machine. You can add transitions and pass events so the machine changes its state and executes actions. Documentation is coming. Downsized with the help of UglifyJS on marijn's website : http://marijnhaverbeke.nl/uglifyjs This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,24 @@ SM = function( a // stores the current state ,b // an object to store all states and their transitions ){ return b={} // Initializes b to an empty object ,{ add:function( // The function to add a state/transition a // The name of the state to add ,c // The event that will trigger the transition ,d // The action to perform ,e // The next state is optional ){ (b[a]=b[a]||{})[c]=[d,e] // Add a state c to object b (or assign default {}) // and use the result to store an array with [ action, nextState ] }, ev:function( // The function to send an event to the state machine c // The name of the event ,d ){ return d=b[a][c], // execute the action for the event corresponding in the current state d&&(d[0](),a=d[1]||a) // and return the next state that is assigned to the current state (for testing purpose) } } } -
podefr revised this gist
Oct 25, 2011 . 5 changed files with 95 additions and 29 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,24 @@ SM = function( a // stores the current state ,b // an object to store all states and their transitions ){ return b={} // Initializes b to an empty object ,{ add:function( // The function to add a state/transition c // The name of the state to add ,d // The event that will trigger the transition ,e // The action to perform ,f // The next state is optional ){ (b[c]=b[c]||{})[d]=[e,f] // Add a state c to object b (or assign default {}) // and use the result to store an array with [ action, nextState ] }, ev:function( // The function to send an event to the state machine c // The name of the event ,g ){ return g=b[a][c], // execute the action for the event corresponding in the current state g&&(g[0](),a=g[1]||a) // and return the next state that is assigned to the current state (for testing purpose) } } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ function(a,b){return b={},{add:function(a,c,d,e){(b[a]=b[a]||{})[c]=[d,e]},ev:function(c,d){return d=b[a][c],d&&(d[0](),a=d[1]||a)}}} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,13 @@ { "name": "StateMachineGenerator", "description": "A state machine generator", "keywords": [ "state", "machine", "generator", "fsm", "design pattern" ] } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ // JsTestDriver TestCase TestCase("SM", { "test SM API": function() { var sm = SM(); assertFunction(sm.add); assertFunction(sm.ev); }, "test SM transits between 2 states": function() { var open=function(){open.called=true}, close=function(){close.called=true}, sm = SM("closed"); // When in closed state, if the event is "open!" then execute the open action and go to opened state. sm.add("closed", "open!", open, "opened"); // the opposite sm.add("opened", "close!", close, "closed"); assertUndefined(open.called); assertEquals("opened", sm.ev("open!")); assertTrue(open.called); assertUndefined(close.called); assertEquals("closed", sm.ev("close!")); assertTrue(close.called); }, "test SM doesn't crash if wrong event in given state": function() { var sm = SM("state"); sm.add("state", "event", function(){}, "nextState"); assertUndefined(sm.ev("crash!")); }, "test the whole diagram": function() { var alarm = function () { alarm.called = true }, open = function () { open.called = true }, thank = function () { thank.called = true}, close = function () { close.called = true}, sm = SM("closed"); sm.add("closed", "pass", alarm); sm.add("closed", "coin", open, "opened"); sm.add("opened", "coin", thank); sm.add("opened", "pass", close, "closed"); assertEquals("closed", sm.ev("pass")); assertTrue(alarm.called); assertEquals("opened", sm.ev("coin")); assertTrue(open.called); assertEquals("opened", sm.ev("coin")); assertTrue(thank.called); assertEquals("closed", sm.ev("pass")); assertTrue(close.called); } }); -
140bytes revised this gist
Jul 28, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ All entries must also be licensed under the [WTFPL](http://sam.zoy.org/wtfpl/) o For more information -------------------- See the [140byt.es](http://140byt.es) site for a showcase of entries (built itself using 140-byte entries!), and follow [@140bytes](http://twitter.com/140bytes) on Twitter. To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to [the wiki](https://github.com/jed/140bytes/wiki/Byte-saving-techniques). -
140bytes revised this gist
Jul 28, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -25,8 +25,8 @@ All entries must also be licensed under the [WTFPL](http://sam.zoy.org/wtfpl/) o For more information -------------------- See the [140byt.es](http://140byt.es) for a showcase of entries built itself using 140-byte entries, and follow [@140bytes](http://twitter.com/140bytes) on Twitter. To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to [the wiki](https://github.com/jed/140bytes/wiki/Byte-saving-techniques). 140byt.es is brought to you by [Jed Schmidt](http://jed.is), with help from Alex Kloss. It was inspired by work from [Thomas Fuchs](http://mir.aculo.us) and [Dustin Diaz](http://www.dustindiaz.com/). -
140bytes revised this gist
Jun 1, 2011 . 1 changed file with 5 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,12 @@ <!DOCTYPE html> <title>Foo</title> <div>Expected value: <b>undefined</b></div> <div>Actual value: <b id="ret"></b></div> <script> // write a small example that shows off the API for your example // and tests it in one fell swoop. var myFunction = function(){ /* the code here should be identical to the entry. */ } document.getElementById( "ret" ).innerHTML = myFunction() </script> -
140bytes revised this gist
Jun 1, 2011 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ <!DOCTYPE html> <body> <div>Expected value: <b>undefined</b></div> <div>Actual value: <b id="ret"></b></div> -
140bytes revised this gist
May 31, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,5 +9,5 @@ var myFunction = function(){ /* the code here should be identical to the entry. */ } var ret = myFunction() document.getElementById( "ret" ).innerHTML = ret </script> -
140bytes revised this gist
May 31, 2011 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ <body> <div>Expected value: <b>undefined</b></div> <div>Actual value: <b id="ret"></b></div> </body> <script> // write a small example that shows off the API for your example // and tests it in one fell swoop. var myFunction = function(){ /* the code here should be identical to the entry. */ } var ret = myFunction() document.getElementById( "ret" ) = ret </script> -
140bytes revised this gist
May 31, 2011 . 3 changed files with 17 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,10 @@ function(){ // make sure // to annotate // your code // so everyone // can learn // from it! // see jed's entries // for examples. } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ function(){/* Your entry, a useful, unique, and valid JavaScript expression that packs as much functionality into 140 bytes as possible. */} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,13 @@ { "name": "theNameOfYourLibWhichMustBeAValidCamelCasedJavaScriptIdentifier", "description": "This should be a short description of your entry.", "keywords": [ "five", "descriptive", "keywords", "or", "fewer" ] } -
140bytes revised this gist
May 26, 2011 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ function(){ /* Rules: (1) anonymous function or IIFE // make sure (2) may execute immediately // to annotate (3) <=140 bytes // your code (4) no globals // so everyone (5) permissive license // can learn (6) have a good time! // from it! */} -
140bytes revised this gist
May 25, 2011 . 3 changed files with 8 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ Rules ----- All entries must exist in an `index.js` file, whose contents are 1. an assignable, valid Javascript expression that 2. contains no more than 140 bytes, and 3. does not leak to the global scope. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ function(){ /* Rules: (1) anonymous function // make sure (2) may execute immediately // to annotate (3) <=140 bytes // your code (4) no globals // so everyone (5) permissive license // can learn (6) have a good time! // from it! */} This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ function(){/******************************************************************************************************************************/} -
140bytes revised this gist
May 23, 2011 . 2 changed files with 14 additions and 21 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,20 +1,13 @@ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004 Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE> Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. You just DO WHAT THE FUCK YOU WANT TO. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ All entries must exist in an `index.js` file, whose contents are 2. contains no more than 140 bytes, and 3. does not leak to the global scope. All entries must also be licensed under the [WTFPL](http://sam.zoy.org/wtfpl/) or equally permissive license. For more information -------------------- -
140bytes revised this gist
May 23, 2011 . 1 changed file with 3 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,12 +16,11 @@ Rules ----- All entries must exist in an `index.js` file, whose contents are 1. an assignable, valid Javascript expression, that 2. contains no more than 140 bytes, and 3. does not leak to the global scope. All entries must also be licensed under a license as or more permitting than the MIT license. For more information -------------------- -
140bytes revised this gist
May 22, 2011 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,8 @@ How to play 2. Modify all the files to according to the rules below. 3. Save your entry and tweet it up! Keep in mind that thanks to the awesome sensibilities of the GitHub team, gists are just repos. So feel free to clone yours and work locally for a more comfortable environment, and to allow commit messages. Rules ----- All entries must exist in an `index.js` file, whose contents are -
140bytes revised this gist
May 21, 2011 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,4 +26,6 @@ For more information The [140byt.es](http://140byt.es) site hasn't launched yet, but for now follow [@140bytes](http://twitter.com/140bytes) on Twitter. To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to [the wiki](https://github.com/jed/140bytes/wiki/Byte-saving-techniques). 140byt.es is brought to you by [Jed Schmidt](http://jed.is). It was inspired by work from [Thomas Fuchs](http://mir.aculo.us) and [Dustin Diaz](http://www.dustindiaz.com/). -
140bytes revised this gist
May 18, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ // [OPTIONAL] A description of your library, phrased as a verb predicate. // The gist description is used by default. "description": "Explain the 140byt.es rules.", // [OPTIONAL] Up to 5 keywords used for indexing. "keywords": [ -
140bytes revised this gist
May 18, 2011 . 1 changed file with 13 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,16 @@ { // [REQUIRED] A name for your library. // This must match /^[a-z_]\w*$/i "name": "140bytes", // [OPTIONAL] A description of your library, phrased as a verb predicate. // The gist description is used by default. "description": "Explain the 140byt.es rules." // [OPTIONAL] Up to 5 keywords used for indexing. "keywords": [ "140bytes", "master", "rules" ] }
NewerOlder