reactivity
Advanced tools
Comparing version 1.1.0 to 1.2.0
// Generated by CoffeeScript 1.6.3 | ||
/* | ||
Base class used by Notifier and Monitor. | ||
It provides a basic framework to manage states. | ||
Implementers must implement | ||
@states ( a hashmap of states to handlers ) | ||
@public_api ( with handlers ) | ||
(function() { | ||
var Base, events, _ref, | ||
__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; }; | ||
It also implements a subset of the EventEmitter API | ||
on, off and emit | ||
*/ | ||
events = require('events'); | ||
/* | ||
Base class used by Notifier and Monitor. | ||
It provides a basic framework to manage states. | ||
Implementers must implement | ||
@states ( a hashmap of states to handlers ) | ||
@public_api ( with handlers ) | ||
It also implements a subset of the EventEmitter API | ||
on, off and emit | ||
*/ | ||
(function() { | ||
var Base, | ||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; | ||
module.exports = Base = (function() { | ||
function Base() {} | ||
module.exports = Base = (function(_super) { | ||
__extends(Base, _super); | ||
function Base() { | ||
_ref = Base.__super__.constructor.apply(this, arguments); | ||
return _ref; | ||
} | ||
Base.prototype.state = 'ready'; | ||
@@ -40,44 +48,28 @@ | ||
Base.prototype.__listeners = null; | ||
/* | ||
__listeners: null | ||
_l: -> @__listeners ?= {} | ||
emit: ( event, e ) -> | ||
if ( ls = @_l()[event] )? | ||
x(e) for x in ls | ||
on: ( event, listener ) -> | ||
arr = ( @_l()[event] ?= [] ) | ||
arr.push listener unless listener in arr | ||
undefined | ||
off: ( event, listener ) -> | ||
l = @_l() | ||
if ( arr = l[event] )? | ||
l[event] = ( x for x in arr when not ( x is listener or x is listener.L ) ) | ||
undefined | ||
once: ( event, listener ) -> | ||
l = (e) => @off event, l ; listener e | ||
l.L = listener | ||
@on event, l | ||
*/ | ||
Base.prototype._l = function(event) { | ||
return this.__listeners != null ? this.__listeners : this.__listeners = {}; | ||
}; | ||
Base.prototype.listeners = function(event) { | ||
return this._l()[event] || []; | ||
}; | ||
Base.prototype.on = function(event, listener) { | ||
var arr, _base; | ||
arr = ((_base = this._l())[event] != null ? (_base = this._l())[event] : _base[event] = []); | ||
if (__indexOf.call(arr, listener) < 0) { | ||
arr.push(listener); | ||
} | ||
return void 0; | ||
}; | ||
Base.prototype.off = function(event, listener) { | ||
var arr, l, x; | ||
l = this._l(); | ||
if ((arr = l[event]) != null) { | ||
l[event] = (function() { | ||
var _i, _len, _results; | ||
_results = []; | ||
for (_i = 0, _len = arr.length; _i < _len; _i++) { | ||
x = arr[_i]; | ||
if (x !== listener) { | ||
_results.push(x); | ||
} | ||
} | ||
return _results; | ||
})(); | ||
} | ||
return void 0; | ||
}; | ||
return Base; | ||
})(); | ||
})(events.EventEmitter); | ||
}).call(this); |
@@ -40,5 +40,8 @@ // Generated by CoffeeScript 1.6.3 | ||
}, | ||
off: function(e, l) { | ||
return _this.off(e, l); | ||
removeListener: function(e, l) { | ||
return _this.removeListener(e, l); | ||
}, | ||
once: function(e, l) { | ||
return _this.once(e, l); | ||
}, | ||
destroy: this.user$destroy, | ||
@@ -52,21 +55,7 @@ state: function() { | ||
Monitor.prototype.handle_cancel = function() { | ||
var x, _i, _len, _ref, _results; | ||
_ref = this.listeners('cancel'); | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
x = _ref[_i]; | ||
_results.push(x()); | ||
} | ||
return _results; | ||
return this.emit('cancel'); | ||
}; | ||
Monitor.prototype.handle_change = function() { | ||
var x, _i, _len, _ref, _results; | ||
_ref = this.listeners('change'); | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
x = _ref[_i]; | ||
_results.push(x()); | ||
} | ||
return _results; | ||
return this.emit('change'); | ||
}; | ||
@@ -73,0 +62,0 @@ |
@@ -43,2 +43,5 @@ // Generated by CoffeeScript 1.6.3 | ||
}; | ||
f.once = function(e, l) { | ||
return _this.once(e, l); | ||
}; | ||
f.state = function() { | ||
@@ -53,10 +56,3 @@ return _this.state; | ||
Notifier.prototype.handle_cancel = function() { | ||
var x, _i, _len, _ref, _results; | ||
_ref = this.listeners('cancel'); | ||
_results = []; | ||
for (_i = 0, _len = _ref.length; _i < _len; _i++) { | ||
x = _ref[_i]; | ||
_results.push(x()); | ||
} | ||
return _results; | ||
return this.emit('cancel'); | ||
}; | ||
@@ -63,0 +59,0 @@ |
@@ -10,3 +10,3 @@ // Generated by CoffeeScript 1.6.3 | ||
stopper = function() { | ||
return current_monitor != null ? current_monitor.destroy() : void 0; | ||
return current_monitor != null ? current_monitor.removeListener('change', iter) : void 0; | ||
}; | ||
@@ -17,6 +17,6 @@ (iter = function() { | ||
if (typeof cb === "function") { | ||
cb(r.error, r.result, r.monitor); | ||
cb(r.error, r.result, r.monitor, stopper); | ||
} | ||
current_monitor = r.monitor; | ||
return current_monitor != null ? current_monitor.onChange(iter) : void 0; | ||
return current_monitor != null ? current_monitor.once('change', iter) : void 0; | ||
})(); | ||
@@ -23,0 +23,0 @@ return stopper; |
{ | ||
"name": "reactivity", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Native Reactivity for Javascript", | ||
@@ -5,0 +5,0 @@ "author": "Aldo Bucchi <aldo.bucchi@gmail.com>", |
21099
432