reactivity
Advanced tools
Comparing version 1.2.3 to 1.3.0
@@ -47,24 +47,2 @@ // Generated by CoffeeScript 1.6.3 | ||
/* | ||
__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 | ||
*/ | ||
return Base; | ||
@@ -71,0 +49,0 @@ |
@@ -9,2 +9,7 @@ // Generated by CoffeeScript 1.6.3 | ||
/* | ||
Internal class that wraps an evaluation | ||
*/ | ||
module.exports = Evaluation = (function() { | ||
@@ -34,2 +39,7 @@ function Evaluation(func) { | ||
/* | ||
An evaluation owns a monitor | ||
*/ | ||
Evaluation.prototype.monitor = function() { | ||
@@ -39,2 +49,8 @@ return this.m != null ? this.m : this.m = new Monitor; | ||
/* | ||
You can request N notifiers | ||
( they will be provisioned by the current monitor ) | ||
*/ | ||
Evaluation.prototype.notifier = function() { | ||
@@ -41,0 +57,0 @@ var _ref; |
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var Base, Monitor, Notifier, | ||
var Base, Monitor, Notifier, util, | ||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
@@ -12,2 +12,4 @@ __hasProp = {}.hasOwnProperty, | ||
util = require('./util'); | ||
module.exports = Monitor = (function(_super) { | ||
@@ -19,35 +21,24 @@ __extends(Monitor, _super); | ||
changed: 'handle_change', | ||
cancelled: 'handle_cancel', | ||
destroyed: null | ||
cancelled: 'handle_cancel' | ||
}; | ||
Monitor.prototype.destroyed_notifiers = 0; | ||
Monitor.prototype.cancelled_notifiers = 0; | ||
function Monitor() { | ||
this.user$destroy = __bind(this.user$destroy, this); | ||
this.notifier$destroy_notifier = __bind(this.notifier$destroy_notifier, this); | ||
this.user$cancel = __bind(this.user$cancel, this); | ||
this.notifier$cancel_notifier = __bind(this.notifier$cancel_notifier, this); | ||
this.evaluation$create_notifier = __bind(this.evaluation$create_notifier, this); | ||
var _this = this; | ||
var f, | ||
_this = this; | ||
this.notifiers = []; | ||
this.public_api = { | ||
onChange: function(f) { | ||
return _this.on('change', f); | ||
}, | ||
onCancel: function(f) { | ||
return _this.on('cancel', f); | ||
}, | ||
on: function(e, l) { | ||
return _this.on(e, l); | ||
}, | ||
removeListener: function(e, l) { | ||
return _this.removeListener(e, l); | ||
}, | ||
once: function(e, l) { | ||
return _this.once(e, l); | ||
}, | ||
destroy: this.user$destroy, | ||
state: function() { | ||
return _this.state; | ||
} | ||
this.public_api = f = function(h) { | ||
return _this.once('change', h); | ||
}; | ||
util.copy_event_emitter_methods(this, f); | ||
f.cancel = function() { | ||
return _this.user$cancel(); | ||
}; | ||
f.state = function() { | ||
return _this.state; | ||
}; | ||
} | ||
@@ -69,4 +60,4 @@ | ||
Monitor.prototype.notifier$destroy_notifier = function() { | ||
if (this.notifiers.length === ++this.destroyed_notifiers) { | ||
Monitor.prototype.notifier$cancel_notifier = function() { | ||
if (this.notifiers.length === ++this.cancelled_notifiers) { | ||
return this.transition('cancelled'); | ||
@@ -76,3 +67,3 @@ } | ||
Monitor.prototype.notifier$fire = function() { | ||
Monitor.prototype.notifier$change = function() { | ||
var _this = this; | ||
@@ -93,5 +84,5 @@ return this.transition('changed', function() { | ||
Monitor.prototype.user$destroy = function() { | ||
Monitor.prototype.user$cancel = function() { | ||
var _this = this; | ||
return this.transition('destroyed', function() { | ||
return this.transition('cancelled', function() { | ||
var x, _i, _len, _ref, _results; | ||
@@ -98,0 +89,0 @@ _ref = _this.notifiers; |
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var Base, Notifier, | ||
var Base, Notifier, util, | ||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, | ||
@@ -10,2 +10,4 @@ __hasProp = {}.hasOwnProperty, | ||
util = require('./util'); | ||
/* | ||
@@ -22,4 +24,3 @@ The Notifier is the main class used when creating reactive functions | ||
cancelled: 'handle_cancel', | ||
fired: null, | ||
destroyed: null | ||
changed: null | ||
}; | ||
@@ -31,24 +32,13 @@ | ||
this.monitor = monitor; | ||
this.user$destroy = __bind(this.user$destroy, this); | ||
this.user$fire = __bind(this.user$fire, this); | ||
this.user$cancel = __bind(this.user$cancel, this); | ||
this.user$change = __bind(this.user$change, this); | ||
this.public_api = f = function() { | ||
return _this.user$fire(); | ||
return _this.user$change(); | ||
}; | ||
f.onCancel = function(l) { | ||
return _this.on('cancel', l); | ||
}; | ||
f.on = function(e, l) { | ||
return _this.on(e, l); | ||
}; | ||
f.off = function(e, l) { | ||
return _this.off(e, l); | ||
}; | ||
f.once = function(e, l) { | ||
return _this.once(e, l); | ||
}; | ||
util.copy_event_emitter_methods(this, f); | ||
f.state = function() { | ||
return _this.state; | ||
}; | ||
f.destroy = this.user$destroy; | ||
f.fire = this.user$fire; | ||
f.cancel = this.user$cancel; | ||
f.change = this.user$change; | ||
} | ||
@@ -60,13 +50,13 @@ | ||
Notifier.prototype.user$fire = function() { | ||
Notifier.prototype.user$change = function() { | ||
var _this = this; | ||
return this.transition('fired', function() { | ||
return _this.monitor.notifier$fire(); | ||
return this.transition('changed', function() { | ||
return _this.monitor.notifier$change(); | ||
}); | ||
}; | ||
Notifier.prototype.user$destroy = function() { | ||
Notifier.prototype.user$cancel = function() { | ||
var _this = this; | ||
return this.transition('destroyed', function() { | ||
return _this.monitor.notifier$destroy_notifier(); | ||
return this.transition('cancelled', function() { | ||
return _this.monitor.notifier$cancel_notifier(); | ||
}); | ||
@@ -73,0 +63,0 @@ }; |
@@ -36,7 +36,7 @@ // Generated by CoffeeScript 1.6.3 | ||
if (monitor != null) { | ||
monitor.onChange(notifier()); | ||
monitor.once('change', notifier()); | ||
} else { | ||
b = notifier(); | ||
stopped = false; | ||
b.onCancel(function() { | ||
b.once('cancel', function() { | ||
return stopped = true; | ||
@@ -43,0 +43,0 @@ }); |
{ | ||
"name": "reactivity", | ||
"version": "1.2.3", | ||
"version": "1.3.0", | ||
"description": "Native Reactivity for Javascript", | ||
@@ -21,7 +21,7 @@ "author": "Aldo Bucchi <aldo.bucchi@gmail.com>", | ||
"type": "git", | ||
"url": "https://github.com/aldonline/reactivity.js.git" | ||
"url": "https://github.com/aldonline/reactivity.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/aldonline/reactivity.js/issues" | ||
"url": "https://github.com/aldonline/reactivity/issues" | ||
} | ||
} |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
13
1
20898
424