mirror of
https://github.com/Hopiu/postal.js.git
synced 2026-03-16 22:20:23 +00:00
8 lines
No EOL
3.1 KiB
JavaScript
8 lines
No EOL
3.1 KiB
JavaScript
/**
|
|
* postal - Pub/Sub library providing wildcard subscriptions, complex message handling, etc. Works server and client-side.
|
|
* Author: Jim Cowart (http://freshbrewedcode.com/jimcowart)
|
|
* Version: v0.9.0-rc1
|
|
* Url: http://github.com/postaljs/postal.js
|
|
* License(s): MIT, GPL
|
|
*/
|
|
(function(t,n){"object"==typeof module&&module.exports?module.exports=function(t){return n(t,this)}:"function"==typeof define&&define.amd?define(["postal"],function(i){return n(i,t)}):t.postal=n(t.postal,t)})(this,function(t){return function(t){var n=function(){var t;return function(n){var i=!1;return _.isString(n)?(i=n===t,t=n):(i=_.isEqual(n,t),t=_.clone(n)),!i}},i=function(){var t=[];return function(n){var i=!_.any(t,function(t){return _.isObject(n)||_.isArray(n)?_.isEqual(n,t):n===t});return i&&t.push(n),i}},e={withDelay:function(t){if(_.isNaN(t))throw"Milliseconds must be a number";return{name:"withDelay",fn:function(n,i,e){setTimeout(function(){n(i,e)},t)}}},defer:function(){return this.withDelay(0)},stopAfter:function(t,n){if(_.isNaN(t)||0>=t)throw"The value provided to disposeAfter (maxCalls) must be a number greater than zero.";var i=_.after(t,n);return{name:"stopAfter",fn:function(t,n,e){i(),t(n,e)}}},withThrottle:function(t){if(_.isNaN(t))throw"Milliseconds must be a number";return{name:"withThrottle",fn:_.throttle(function(t,n,i){t(n,i)},t)}},withDebounce:function(t,n){if(_.isNaN(t))throw"Milliseconds must be a number";return{name:"debounce",fn:_.debounce(function(t,n,i){t(n,i)},t,!!n)}},withConstraint:function(t){if(!_.isFunction(t))throw"Predicate constraint must be a function";return{name:"withConstraint",fn:function(n,i,e){t.call(this,i,e)&&n.call(this,i,e)}}},distinct:function(t){t=t||{};var e=function(t){return t[0]},o=t.all?new i(e):new n(e);return{name:"distinct",fn:function(t,n,i){o(n)&&t(n,i)}}}};t.prototype.defer=function(){return this.callback.before(e.defer()),this},t.prototype.disposeAfter=function(t){var n=this;return n.callback.before(e.stopAfter(t,function(){n.unsubscribe.call(n)})),n},t.prototype.distinctUntilChanged=function(){return this.callback.before(e.distinct()),this},t.prototype.distinct=function(){return this.callback.before(e.distinct({all:!0})),this},t.prototype.once=function(){return this.disposeAfter(1),this},t.prototype.withConstraint=function(t){return this.callback.before(e.withConstraint(t)),this},t.prototype.withConstraints=function(t){for(;t.length;)this.callback.before(e.withConstraint(t.shift()));return this},t.prototype.withDebounce=function(t,n){return this.callback.before(e.withDebounce(t,n)),this},t.prototype.withDelay=function(t){return this.callback.before(e.withDelay(t)),this},t.prototype.withThrottle=function(t){return this.callback.before(e.withThrottle(t)),this},t.prototype.subscribe=function(t){return this.callback=new Conduit({target:t,context:this}),this},t.prototype.withContext=function(t){return this.callback.context(t),this},t.prototype.after=function(){this.callback.after.apply(this,arguments)},t.prototype.before=function(){this.callback.before.apply(this,arguments)},ChannelDefinition.prototype.initialize=function(){var t=this.publish;this.publish=new Conduit({target:t,context:this})}}(t.SubscriptionDefinition),t}); |