mirror of
https://github.com/Hopiu/postal.js.git
synced 2026-03-16 22:20:23 +00:00
added .once() shortcut to SubscriptionDefinition and related test
This commit is contained in:
parent
11b3d00024
commit
5c2727acfd
12 changed files with 69 additions and 20 deletions
|
|
@ -4,17 +4,17 @@
|
|||
License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license)
|
||||
Version 0.7.3
|
||||
*/
|
||||
(function ( root, doc, factory ) {
|
||||
(function ( root, factory ) {
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define( ["underscore"], function ( _ ) {
|
||||
return factory( _, root, doc );
|
||||
return factory( _, root );
|
||||
} );
|
||||
} else {
|
||||
// Browser globals
|
||||
factory( root._, root, doc );
|
||||
factory( root._, root );
|
||||
}
|
||||
}( this, document, function ( _, global, document, undefined ) {
|
||||
}( this, function ( _, global, undefined ) {
|
||||
|
||||
var DEFAULT_CHANNEL = "/",
|
||||
DEFAULT_PRIORITY = 50,
|
||||
|
|
@ -169,6 +169,10 @@
|
|||
return this;
|
||||
},
|
||||
|
||||
once: function() {
|
||||
this.disposeAfter(1);
|
||||
},
|
||||
|
||||
withConstraint : function ( predicate ) {
|
||||
if ( !_.isFunction( predicate ) ) {
|
||||
throw "Predicate constraint must be a function";
|
||||
|
|
|
|||
2
example/amd/js/libs/postal/postal.min.js
vendored
2
example/amd/js/libs/postal/postal.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -4,17 +4,17 @@
|
|||
License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license)
|
||||
Version 0.7.3
|
||||
*/
|
||||
(function ( root, doc, factory ) {
|
||||
(function ( root, factory ) {
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define( ["underscore"], function ( _ ) {
|
||||
return factory( _, root, doc );
|
||||
return factory( _, root );
|
||||
} );
|
||||
} else {
|
||||
// Browser globals
|
||||
factory( root._, root, doc );
|
||||
factory( root._, root );
|
||||
}
|
||||
}( this, document, function ( _, global, document, undefined ) {
|
||||
}( this, function ( _, global, undefined ) {
|
||||
|
||||
var DEFAULT_CHANNEL = "/",
|
||||
DEFAULT_PRIORITY = 50,
|
||||
|
|
@ -169,6 +169,10 @@
|
|||
return this;
|
||||
},
|
||||
|
||||
once: function() {
|
||||
this.disposeAfter(1);
|
||||
},
|
||||
|
||||
withConstraint : function ( predicate ) {
|
||||
if ( !_.isFunction( predicate ) ) {
|
||||
throw "Predicate constraint must be a function";
|
||||
|
|
|
|||
2
example/node/client/js/lib/postal.min.js
vendored
2
example/node/client/js/lib/postal.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -161,6 +161,10 @@ SubscriptionDefinition.prototype = {
|
|||
return this;
|
||||
},
|
||||
|
||||
once: function() {
|
||||
this.disposeAfter(1);
|
||||
},
|
||||
|
||||
withConstraint : function ( predicate ) {
|
||||
if ( !_.isFunction( predicate ) ) {
|
||||
throw "Predicate constraint must be a function";
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@
|
|||
License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license)
|
||||
Version 0.7.3
|
||||
*/
|
||||
(function ( root, doc, factory ) {
|
||||
(function ( root, factory ) {
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define( ["underscore"], function ( _ ) {
|
||||
return factory( _, root, doc );
|
||||
return factory( _, root );
|
||||
} );
|
||||
} else {
|
||||
// Browser globals
|
||||
factory( root._, root, doc );
|
||||
factory( root._, root );
|
||||
}
|
||||
}( this, document, function ( _, global, document, undefined ) {
|
||||
}( this, function ( _, global, undefined ) {
|
||||
|
||||
var DEFAULT_CHANNEL = "/",
|
||||
DEFAULT_PRIORITY = 50,
|
||||
|
|
@ -169,6 +169,10 @@
|
|||
return this;
|
||||
},
|
||||
|
||||
once: function() {
|
||||
this.disposeAfter(1);
|
||||
},
|
||||
|
||||
withConstraint : function ( predicate ) {
|
||||
if ( !_.isFunction( predicate ) ) {
|
||||
throw "Predicate constraint must be a function";
|
||||
|
|
|
|||
2
example/standard/js/postal.min.js
vendored
2
example/standard/js/postal.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -4,17 +4,17 @@
|
|||
License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license)
|
||||
Version 0.7.3
|
||||
*/
|
||||
(function ( root, doc, factory ) {
|
||||
(function ( root, factory ) {
|
||||
if ( typeof define === "function" && define.amd ) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define( ["underscore"], function ( _ ) {
|
||||
return factory( _, root, doc );
|
||||
return factory( _, root );
|
||||
} );
|
||||
} else {
|
||||
// Browser globals
|
||||
factory( root._, root, doc );
|
||||
factory( root._, root );
|
||||
}
|
||||
}( this, document, function ( _, global, document, undefined ) {
|
||||
}( this, function ( _, global, undefined ) {
|
||||
|
||||
var DEFAULT_CHANNEL = "/",
|
||||
DEFAULT_PRIORITY = 50,
|
||||
|
|
@ -169,6 +169,10 @@
|
|||
return this;
|
||||
},
|
||||
|
||||
once: function() {
|
||||
this.disposeAfter(1);
|
||||
},
|
||||
|
||||
withConstraint : function ( predicate ) {
|
||||
if ( !_.isFunction( predicate ) ) {
|
||||
throw "Predicate constraint must be a function";
|
||||
|
|
|
|||
2
lib/browser/postal.min.js
vendored
2
lib/browser/postal.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -161,6 +161,10 @@ SubscriptionDefinition.prototype = {
|
|||
return this;
|
||||
},
|
||||
|
||||
once: function() {
|
||||
this.disposeAfter(1);
|
||||
},
|
||||
|
||||
withConstraint : function ( predicate ) {
|
||||
if ( !_.isFunction( predicate ) ) {
|
||||
throw "Predicate constraint must be a function";
|
||||
|
|
|
|||
|
|
@ -156,6 +156,27 @@ describe( "Postal", function () {
|
|||
expect( msgReceivedCnt ).to.be( 5 );
|
||||
} );
|
||||
} );
|
||||
describe( "When subscribing with once()", function () {
|
||||
var msgReceivedCnt = 0;
|
||||
before( function () {
|
||||
channel = postal.channel( { channel : "MyChannel", topic : "MyTopic" } );
|
||||
subscription = channel.subscribe( function ( data ) {
|
||||
msgReceivedCnt++;
|
||||
} ).once();
|
||||
channel.publish( "Testing123" );
|
||||
channel.publish( "Testing123" );
|
||||
channel.publish( "Testing123" );
|
||||
channel.publish( "Testing123" );
|
||||
channel.publish( "Testing123" );
|
||||
channel.publish( "Testing123" );
|
||||
} );
|
||||
after( function () {
|
||||
postal.utils.reset();
|
||||
} );
|
||||
it( "subscription callback should be invoked 1 time", function () {
|
||||
expect( msgReceivedCnt ).to.be( 1 );
|
||||
} );
|
||||
} );
|
||||
describe( "When subscribing and ignoring duplicates", function () {
|
||||
var subInvokedCnt = 0;
|
||||
before( function () {
|
||||
|
|
|
|||
|
|
@ -72,6 +72,10 @@ SubscriptionDefinition.prototype = {
|
|||
return this;
|
||||
},
|
||||
|
||||
once: function() {
|
||||
this.disposeAfter(1);
|
||||
},
|
||||
|
||||
withConstraint : function ( predicate ) {
|
||||
if ( !_.isFunction( predicate ) ) {
|
||||
throw "Predicate constraint must be a function";
|
||||
|
|
|
|||
Loading…
Reference in a new issue