state
Version:
First-class states
84 lines (70 loc) • 2.49 kB
JavaScript
// Generated by CoffeeScript 1.6.3
(function() {
var State, Transition,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
State = require('./state');
module.exports = Transition = (function(_super) {
var VIA_PROTO;
__extends(Transition, _super);
VIA_PROTO = Transition.VIA_PROTO;
function Transition(target, source, expression, callback) {
var root, _ref;
this.name = expression.name || null;
this.superstate = source;
this.root = root = source.root;
if (target.root !== root) {
throw ReferenceError;
}
this.owner = root.owner;
this.target = target;
this.source = source;
this.origin = (_ref = source.origin) != null ? _ref : source;
this.callback = callback;
this.action = expression.action || null;
this._ = new this.Metaobject;
this.aborted = false;
this.initialize(expression);
}
Transition.prototype.linearize = function() {
var superstate, _ref, _ref1;
superstate = this.superstate;
return (_ref = (_ref1 = superstate.order) != null ? _ref1.slice(0) : void 0) != null ? _ref : superstate.linearize();
};
Transition.prototype.start = function() {
var action;
this.aborted = false;
this.emit('start', arguments, VIA_PROTO);
if (action = this.action) {
action.apply(this, arguments);
return this;
} else {
return this.end.apply(this, arguments);
}
};
Transition.prototype.abort = function() {
this.aborted = true;
this.callback = null;
this.emit('abort', arguments, VIA_PROTO);
return this;
};
Transition.prototype.end = function() {
var _ref;
if (!this.aborted) {
this.emit('end', arguments, VIA_PROTO);
if ((_ref = this.callback) != null) {
_ref.apply(this.root, arguments);
}
}
this.destroy();
return this.target;
};
Transition.prototype.destroy = function() {
if (this.source instanceof Transition) {
this.source.destroy();
}
return this.target = this.superstate = this.root = null;
};
return Transition;
})(State);
}).call(this);