This file contains 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 characters
( function ( $, undefined ) { | |
function Animal () { | |
State( this, 'consciousness', { | |
die: function () { this.consciousState.change( 'Dead' ); }, | |
Awake: { | |
breathe: function () { return 'huff puff'; }, | |
heard: function ( noise ) { | |
if ( noise == "Boo!" ) { |
This file contains 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 characters
( function ( $, undefined ) { | |
var Chronograph = $.extend( true, | |
function Chronograph () { | |
this.controller = new Chronograph.Controller( this ); | |
this.model = new Chronograph.Model( this.controller ); | |
this.view = new Chronograph.View( this.controller ); | |
this.engine = new Chronograph.Engine( this ); | |
}, { |
This file contains 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 characters
function Animal () { | |
this.move = function () { return 0; }; | |
State( this, { | |
Stationary: { | |
move: function () { return false; } | |
}, | |
Moving: { | |
move: function () { return true; } | |
} | |
}, 'Stationary' ); |
This file contains 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 characters
state = require 'state' | |
class Hipster | |
emote: -> ":|" | |
state @::, | |
Stoked: | |
emote: -> ":)" | |
Bummed: | |
emote: -> ":(" |
This file contains 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 characters
state = require 'state' | |
io = require 'some-imaginary-io-module' | |
owner = -> @owner() | |
class TextDocument | |
constructor: (@url) -> | |
text = '' | |
@text = -> text | |
@edit = (newText) -> text = newText; @ |
This file contains 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 characters
# # State attributes | |
# ## Declaration | |
state = require 'state' | |
class Emo | |
state @::, 'abstract history' | |
Happy: state 'initial retained' | |
emote: -> ":)" |
This file contains 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 characters
var Z = require('zcore'); | |
function H () { | |
var NIL = Z.NIL, | |
h = this.history = [ | |
{}, | |
{ a: 1, b: 2 }, | |
{ b: NIL, d: 4 }, | |
{ a: NIL, e: 5 }, |
This file contains 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 characters
function Seeker () { | |
var me = this, | |
knowledge = null; | |
function learn ( secret ) { knowledge = secret; } | |
this.ask = function ( whom ) { | |
whom.tell( me, learn ); | |
}; | |
this.spill = function () { |
This file contains 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 characters
{ | |
// ... , | |
// #### method | |
// | |
// Retrieves the named method held on this state. If no method is found, step through | |
// this state’s protostate chain to find one. If no method is found there, step up the | |
// superstate hierarchy and repeat the search. | |
method: function ( methods ) { | |
return function ( |
This file contains 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 characters
createEventEmitter = ( add, remove ) -> | |
types = {} | |
this[ add or 'addListener' ] = ( type, fn, context ) -> | |
( types[ type ] ||= [] ).push fn: fn, context: context or this | |
this[ remove or 'removeListener' ] = ( type, fn ) -> | |
for listener, index in list = types[ type ] | |
if fn is listener.fn then list.splice index, 1; return fn |
OlderNewer