// setup namespace Zymonic.Process = {}; // base process // don't do anything here, makes it easy to establish inheritance Zymonic.Process.Process = function() {}; // init function Zymonic.Process.Process.prototype.init = function(args) { for (var key in args) { this[key] = args[key]; } if (this.ident != "") { Zymonic.add_to_lookup('Process', this.ident, this); } // setup handlers and empty transitions list this.transitions = []; this.transition_run_handlers = {}; }; // function to set a handler for when any transition is run Zymonic.Process.Process.prototype.addTransitionRunCallback = function(key, fn) { // overwrite any existing handler with that key this.transition_run_handlers[key] = fn; }; // function to register a transition with a process Zymonic.Process.Process.prototype.registerTransition = function(transition) { this.transitions.push(transition); // setup a callback on the transition to run any of the handlers on this process var process = this; transition.addRunCallback(this.ident, function(xml, block_id) { for (var key in process.transition_run_handlers) { process.transition_run_handlers[key](xml, block_id, transition); } }); };