UNPKG

state

Version:

First-class states

141 lines (131 loc) 4.36 kB
// Generated by CoffeeScript 1.6.3 (function() { var global; global = this; module.exports = function(state) { var _ref, _this = this; if (state == null) { state = this; } this.VERSION = '0.2.0'; this.options = { memoizeProtostates: true, useDispatchTables: false }; this.O = (_ref = require('omicron'), this.env = _ref.env, this.NIL = _ref.NIL, _ref); this.noConflict = (function() { var original; original = global.state; return function() { global.state = original; return this; }; })(); this.bitfield = function(object, names, offset) { var index, key, _i, _len; if (object == null) { object = {}; } if (offset == null) { offset = 0; } if (typeof names === 'string') { names = names.split(/\s+/); } for (index = _i = 0, _len = names.length; _i < _len; index = ++_i) { key = names[index]; object[key] = 1 << index + offset; } return object; }; this.debug = function() { if (_this.env.debug) { return console.log.apply(console, arguments); } }; this.bind = (function() { var StateBoundFunction, bind; bind = function(fn) { return new StateBoundFunction(fn); }; bind["class"] = StateBoundFunction = (function() { StateBoundFunction.prototype.type = 'state-bound-function'; function StateBoundFunction(fn) { this.fn = fn; } return StateBoundFunction; })(); return bind; })(); this.fix = (function() { var StateFixedFunction, fix; fix = function(fn) { return new StateFixedFunction(fn); }; fix["class"] = StateFixedFunction = (function() { StateFixedFunction.prototype.type = 'state-fixed-function'; function StateFixedFunction(fn) { this.fn = fn; } return StateFixedFunction; })(); return fix; })(); this.own = (function() { var rxAccessor; rxAccessor = /([$_A-Za-z][$\w]*)::(.*)/; return function(owner, selector, expr) { var accessorName, instated, match, _ref1; if (rxAccessor.test(selector)) { _ref1 = rxAccessor.exec(selector), match = _ref1[0], accessorName = _ref1[1], selector = _ref1[2]; } else { accessorName = 'state'; } if (!(instated = owner[accessorName](selector))) { return null; } if (instated.owner === owner) { return instated[instated.isVirtual() && 'realize' || 'mutate'](expr); } else { return instated.virtualize(owner[accessorName]('')).realize(expr); } }; })(); this.extend = function(parastates, attributes, expression) { if (typeof attributes !== 'string') { expression = attributes; attributes = ''; } if (expression == null) { expression = {}; } expression.parastates = parastates; return state(attributes, expression); }; this.rxTransitionArrow = /^\s*([\-=]>)\s*(.*)/; this.transitionArrowMethods = { '->': 'change', '=>': 'changeTo' }; this.STATE_ATTRIBUTE_MODIFIERS = "mutable finite static immutable\ninitial conclusive final\nabstract concrete default\nreflective\nhistory retained shallow versioned\nconcurrent"; this.STATE_EXPRESSION_CATEGORIES = 'parastates data methods events guards substates transitions'; this.STATE_EXPRESSION_CATEGORY_SYNONYMS = { extend: 'parastates', "extends": 'parastates', states: 'substates' }; this.STATE_EVENT_TYPES = 'construct depart exit enter arrive destroy mutate noSuchMethod'; this.GUARD_ACTIONS = 'admit release'; this.TRANSITION_PROPERTIES = 'origin source target action conjugate'; this.TRANSITION_EXPRESSION_CATEGORIES = 'methods events guards'; this.TRANSITION_EVENT_TYPES = 'construct destroy enter exit start end abort'; this.STATE_ATTRIBUTES = this.bitfield({ NORMAL: 0 }, "INCIPIENT\nATOMIC\nDESTROYED\nVIRTUAL\nPARASTATIC" + ' ' + this.STATE_ATTRIBUTE_MODIFIERS.toUpperCase()); this.TRAVERSAL_FLAGS = this.bitfield({ VIA_NONE: 0, VIA_ALL: ~0 }, "VIA_SUB\nVIA_SUPER\nVIA_PROTO"); }; }).call(this);