Comparing version 0.0.5 to 0.0.6
@@ -5,3 +5,3 @@ { | ||
"description": "Observable functions", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"homepage": "https://github.com/ifrost/off", | ||
@@ -8,0 +8,0 @@ "authors": [ |
@@ -1,1 +0,1 @@ | ||
!function(n,r){"function"==typeof define&&define.amd?define(function(){return n.off=r()}):"object"==typeof module&&module.exports?module.exports=n.off=r():n.off=r()}(this,function(){var n=function(n,r){var t=[],e=[];n=n||function(){};var o=function(){var u,f,i,c=r||this;return u=Array.prototype.slice.call(arguments,0),(f=e.some(function(n){return n.apply(this,u)}))?void 0:(i=n.apply(this,u),o.lock?o.lock=!1:t.forEach(function(n){i instanceof Function&&i._off?i.add(n):n.call(c,i)}),i)};return o.before=function(n,r){return r=r||{},(-1===e.indexOf(n)||r.force_add)&&e.push(n),o},o.add=function(n,r){return r=r||{},(-1===t.indexOf(n)||r.force_add)&&t.push(n),o},o.remove=function(n){var r=t.indexOf(n);-1!==r&&t.splice(r,1)},o._off=!0,o.func=n,o};return n.signal=function(){return n(function(n){return n})},n.property=function(r,t){var e,o,u=r,f={};return t=t||function(n,r){return r()===n&&(r.property.lock=!0),r(n)},e=n(function(n,r){return 0===arguments.length&&r!==f?(e.lock=!0,u):t(n,o)}),e.bind=function(n){e.add(n),void 0!==e()&&n(e())},e.reset=function(){return e(f)},o=function(n){return arguments.length&&(u=n),u},o.property=e,e.property=!0,e},n.async=function(r,t){var e=null;return n(function(){var o;t&&e&&(e.lock=!0),e=o=n(function(n){return n},this);var u=Array.prototype.slice.call(arguments,0).concat(o);return r.apply(this,u),o})},n.deferred=function(r,t){var e,o,u,f=!1,i=null,c=n.signal();return o=n(function(){return i=Array.prototype.slice.call(arguments,0),e=c,f?c:(f=!0,t(function(){u=r.apply(this,i),f=!1,c(u)}),c)})},n.decorate=function(r){for(var t in r)"function"!=typeof r[t]||r[t]._off||(r[t]=n(r[t]));return r},n}); | ||
!function(n,r){"function"==typeof define&&define.amd?define(function(){return n.off=r()}):"object"==typeof module&&module.exports?module.exports=n.off=r():n.off=r()}(this,function(){var n=function(n,r){var t=[],e=[];n=n||function(){};var o=function(){var n,u,f,c=r||this;return n=Array.prototype.slice.call(arguments,0),(u=e.some(function(r){return r.apply(this,n)}))?void 0:(f=o.func.apply(c,n),o.lock?o.lock=!1:t.forEach(function(n){f instanceof Function&&f._off?f.add(n):n.call(c,f)}),f)};return o.before=function(n,r){return r=r||{},(-1===e.indexOf(n)||r.force_add)&&e.push(n),o},o.add=function(n,r){return r=r||{},(-1===t.indexOf(n)||r.force_add)&&t.push(n),o},o.override=function(n){var r=o.func;o.func=function(){var t=Array.prototype.slice.call(arguments,0);return t.push(r.bind(this)),n.apply(this,t)}},o.remove=function(n){var r=t.indexOf(n);-1!==r&&t.splice(r,1)},o._off=!0,o.func=n,o};return n.signal=function(){return n(function(n){return n})},n.property=function(r,t){var e,o,u=r,f={};return t=t||function(n,r){return r()===n&&(r.property.lock=!0),r(n)},e=n(function(n,r){return 0===arguments.length&&r!==f?(e.lock=!0,u):t(n,o)}),e.bind=function(n){e.add(n),void 0!==e()&&n(e())},e.reset=function(){return e(f)},o=function(n){return arguments.length&&(u=n),u},o.property=e,e.property=!0,e},n.async=function(r,t){var e=null;return n(function(){var o;t&&e&&(e.lock=!0),e=o=n(function(n){return n},this);var u=Array.prototype.slice.call(arguments,0).concat(o);return r.apply(this,u),o})},n.deferred=function(r,t){var e,o,u,f=!1,c=null,i=n.signal();return o=n(function(){return c=Array.prototype.slice.call(arguments,0),e=i,f?i:(f=!0,t(function(){u=r.apply(this,c),f=!1,i(u)}),i)})},n.decorate=function(r){for(var t in r)"function"!=typeof r[t]||r[t]._off||(r[t]=n(r[t]));return r},n}); |
15
off.js
@@ -32,3 +32,3 @@ (function (root, factory) { | ||
result = func.apply(this, args); | ||
result = runner.func.apply(self, args); | ||
@@ -56,3 +56,3 @@ if (runner.lock) { | ||
return runner; | ||
} | ||
}; | ||
@@ -67,2 +67,11 @@ runner.add = function (handler, options) { | ||
runner.override = function(override) { | ||
var func = runner.func; | ||
runner.func = function() { | ||
var args = Array.prototype.slice.call(arguments, 0); | ||
args.push(func.bind(this)); | ||
return override.apply(this, args); | ||
} | ||
}; | ||
runner.remove = function (handler) { | ||
@@ -174,5 +183,5 @@ var index = _handlers.indexOf(handler); | ||
return obj; | ||
} | ||
}; | ||
return off; | ||
}); |
{ | ||
"name": "off", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Observable functions", | ||
@@ -5,0 +5,0 @@ "main": "off.js", |
@@ -224,2 +224,26 @@ describe('off', function () { | ||
it('should allow to override functions', function(){ | ||
var base = { | ||
create_text: off(function(value){ | ||
this.text = value; | ||
return value; | ||
}) | ||
}; | ||
var foo = Object.create(base); | ||
foo.create_text.override(function(value, $super){ | ||
this.text = 'foo: ' + $super(value); | ||
return this.text; | ||
}); | ||
var bar = Object.create(foo); | ||
bar.create_text.override(function(value, $super){ | ||
this.text = $super(value) + '!'; | ||
return this.text; | ||
}); | ||
bar.create_text('test'); | ||
expect(bar.text).toBe('foo: test!'); | ||
}); | ||
describe('signal', function () { | ||
@@ -226,0 +250,0 @@ |
Sorry, the diff of this file is not supported yet
34867
455