Skip to content

Commit

Permalink
mithgrid current
Browse files Browse the repository at this point in the history
  • Loading branch information
jgsmith committed May 16, 2012
1 parent 1933114 commit 0d31f09
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 8 deletions.
56 changes: 50 additions & 6 deletions dist/mithgrid.js
Expand Up @@ -197,28 +197,72 @@
return that;
};
MITHGrid.initEventFirer = function(isPreventable, isUnicast, hasMemory) {
var callbackFlags, callbacks, that;
var adder, callbackFlags, callbackFns, callbacks, firer, memory, oldAdder, oldFirer, remover, that;
that = {
isPreventable: !!isPreventable,
isUnicast: !!isUnicast,
hasMemory: !!hasMemory
};
callbackFlags = [];
if (that.isPreventable) callbackFlags.push("stopOnFalse");
if (that.isUnicast) callbackFlags.push("unique");
if (that.hasMemory) callbackFlags.push("memory");
callbacks = $.Callbacks(callbackFlags.join(" "));
that.addListener = function(listener) {
adder = function(listener) {
return callbacks.add(listener);
};
that.removeListener = function(listener) {
remover = function(listener) {
return callbacks.remove(listener);
};
that.fire = function() {
firer = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return callbacks.fire.apply(callbacks, args);
};
if (that.isUnicast) {
callbackFns = [];
adder = function(listener) {
return callbackFns.push(listener);
};
remover = function(listener) {
var fn;
return callbackFns = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = callbackFns.length; _i < _len; _i++) {
fn = callbackFns[_i];
if (fn !== listener) _results.push(fn);
}
return _results;
})();
};
callbacks.add(function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
if (callbackFns.length > 0) {
return callbackFns[0].apply(callbackFns, args);
}
});
} else if (that.hasMemory) {
memory = [];
oldAdder = adder;
adder = function(listener) {
var m, _i, _len;
for (_i = 0, _len = memory.length; _i < _len; _i++) {
m = memory[_i];
listener.apply(null, m);
}
return oldAdder(listener);
};
oldFirer = firer;
firer = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
memory.push(args);
return oldFirer.apply(null, args);
};
}
that.addListener = adder;
that.removeListener = remover;
that.fire = firer;
return that;
};
initViewCounter = 0;
Expand Down

0 comments on commit 0d31f09

Please sign in to comment.