mirror of
https://github.com/Hopiu/postal.js.git
synced 2026-03-16 22:20:23 +00:00
Set 'this' context of constraints to match that of the callback. Added tests & removed jshint dependency temporarily
This commit is contained in:
parent
31675a7d1c
commit
68f833cdc4
13 changed files with 37 additions and 26 deletions
|
|
@ -17,5 +17,5 @@
|
|||
"/node/postal.js" : "./example/node/messaging"
|
||||
}
|
||||
},
|
||||
"dependencies": [ "anvil.http", "anvil.uglify", "anvil.jshint" ]
|
||||
"dependencies": [ "anvil.http", "anvil.uglify" ]
|
||||
}
|
||||
|
|
@ -312,10 +312,10 @@
|
|||
_.each( _.clone( topic ), function ( subDef ) {
|
||||
if ( postal.configuration.resolver.compare( subDef.topic, envelope.topic ) ) {
|
||||
if ( _.all( subDef.constraints, function ( constraint ) {
|
||||
return constraint( envelope.data, envelope );
|
||||
return constraint.call(subDef.context, envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.callback.call( subDef.context, envelope.data, envelope );
|
||||
subDef.onHandled();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
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
|
|
@ -312,10 +312,10 @@
|
|||
_.each( _.clone( topic ), function ( subDef ) {
|
||||
if ( postal.configuration.resolver.compare( subDef.topic, envelope.topic ) ) {
|
||||
if ( _.all( subDef.constraints, function ( constraint ) {
|
||||
return constraint( envelope.data, envelope );
|
||||
return constraint.call(subDef.context, envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.callback.call( subDef.context, envelope.data, envelope );
|
||||
subDef.onHandled();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
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
|
|
@ -304,10 +304,10 @@ var localBus = {
|
|||
_.each( _.clone( topic ), function ( subDef ) {
|
||||
if ( postal.configuration.resolver.compare( subDef.topic, envelope.topic ) ) {
|
||||
if ( _.all( subDef.constraints, function ( constraint ) {
|
||||
return constraint( envelope.data, envelope );
|
||||
return constraint.call(subDef.context, envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.callback.call( subDef.context, envelope.data, envelope );
|
||||
subDef.onHandled();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -312,10 +312,10 @@
|
|||
_.each( _.clone( topic ), function ( subDef ) {
|
||||
if ( postal.configuration.resolver.compare( subDef.topic, envelope.topic ) ) {
|
||||
if ( _.all( subDef.constraints, function ( constraint ) {
|
||||
return constraint( envelope.data, envelope );
|
||||
return constraint.call(subDef.context, envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.callback.call( subDef.context, envelope.data, envelope );
|
||||
subDef.onHandled();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
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
|
|
@ -312,10 +312,10 @@
|
|||
_.each( _.clone( topic ), function ( subDef ) {
|
||||
if ( postal.configuration.resolver.compare( subDef.topic, envelope.topic ) ) {
|
||||
if ( _.all( subDef.constraints, function ( constraint ) {
|
||||
return constraint( envelope.data, envelope );
|
||||
return constraint.call(subDef.context, envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.callback.call( subDef.context, envelope.data, envelope );
|
||||
subDef.onHandled();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
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
|
|
@ -304,10 +304,10 @@ var localBus = {
|
|||
_.each( _.clone( topic ), function ( subDef ) {
|
||||
if ( postal.configuration.resolver.compare( subDef.topic, envelope.topic ) ) {
|
||||
if ( _.all( subDef.constraints, function ( constraint ) {
|
||||
return constraint( envelope.data, envelope );
|
||||
return constraint.call(subDef.context, envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.callback.call( subDef.context, envelope.data, envelope );
|
||||
subDef.onHandled();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ describe( "SubscriptionDefinition", function () {
|
|||
expect( sDef.onHandled ).to.be( NO_OP );
|
||||
} );
|
||||
it( "should default the context", function () {
|
||||
expect( sDef.context ).to.be(null);
|
||||
expect( sDef.context ).to.be( null );
|
||||
} );
|
||||
it( "should fire the subscription.created message", function () {
|
||||
expect( caughtSubscribeEvent ).to.be( true );
|
||||
|
|
@ -81,12 +81,23 @@ describe( "SubscriptionDefinition", function () {
|
|||
} );
|
||||
|
||||
describe( "When setting the context", function () {
|
||||
var obj = {},
|
||||
sDefd = new SubscriptionDefinition( "TestChannel", "TestTopic", NO_OP ).withContext( obj );
|
||||
var obj = { name : "Rose" },
|
||||
name,
|
||||
sDefd = new SubscriptionDefinition( "TestChannel", "TestTopic", NO_OP )
|
||||
.withContext( obj )
|
||||
.withConstraint( function ( d, e ) {
|
||||
name = this.name;
|
||||
return true;
|
||||
} );
|
||||
|
||||
postal.publish({ channel: "TestChannel", topic: "TestTopic", data: "Oh, hai"})
|
||||
|
||||
it( "Should set context", function () {
|
||||
expect( sDefd.context ).to.be( obj );
|
||||
} );
|
||||
it( "Should apply context to predicate/constraint", function () {
|
||||
expect( name ).to.be( "Rose" );
|
||||
} );
|
||||
} );
|
||||
|
||||
describe( "When setting priority", function () {
|
||||
|
|
@ -111,7 +122,7 @@ describe( "SubscriptionDefinition", function () {
|
|||
describe( "When deferring the callback", function () {
|
||||
var results = [], sDefe;
|
||||
|
||||
it( "Should defer the callback", function (done) {
|
||||
it( "Should defer the callback", function ( done ) {
|
||||
sDefe = new SubscriptionDefinition( "TestChannel", "TestTopic", function ( data ) {
|
||||
results.push( data );
|
||||
expect( results[0] ).to.be( "first" );
|
||||
|
|
@ -127,7 +138,7 @@ describe( "SubscriptionDefinition", function () {
|
|||
describe( "When delaying the callback", function () {
|
||||
var results = [], sDefe;
|
||||
|
||||
it( "Should delay the callback", function (done) {
|
||||
it( "Should delay the callback", function ( done ) {
|
||||
sDefe = new SubscriptionDefinition( "TestChannel", "TestTopic", function ( data ) {
|
||||
results.push( data );
|
||||
expect( results[0] ).to.be( "first" );
|
||||
|
|
@ -145,7 +156,7 @@ describe( "SubscriptionDefinition", function () {
|
|||
results.push( data );
|
||||
} ).withDebounce( 800 );
|
||||
|
||||
it( "should have only invoked debounced callback once", function (done) {
|
||||
it( "should have only invoked debounced callback once", function ( done ) {
|
||||
sDefe.callback( 1 ); // starts the two second clock on debounce
|
||||
setTimeout( function () {
|
||||
sDefe.callback( 2 );
|
||||
|
|
@ -176,7 +187,7 @@ describe( "SubscriptionDefinition", function () {
|
|||
results.push( data );
|
||||
} ).withThrottle( 500 );
|
||||
|
||||
it( "should have only invoked throttled callback twice", function (done) {
|
||||
it( "should have only invoked throttled callback twice", function ( done ) {
|
||||
sDefe.callback( 1 ); // starts the two second clock on debounce
|
||||
setTimeout( function () {
|
||||
sDefe.callback( 800 );
|
||||
|
|
|
|||
|
|
@ -40,10 +40,10 @@ var localBus = {
|
|||
_.each( _.clone( topic ), function ( subDef ) {
|
||||
if ( postal.configuration.resolver.compare( subDef.topic, envelope.topic ) ) {
|
||||
if ( _.all( subDef.constraints, function ( constraint ) {
|
||||
return constraint( envelope.data, envelope );
|
||||
return constraint.call(subDef.context, envelope.data, envelope );
|
||||
} ) ) {
|
||||
if ( typeof subDef.callback === 'function' ) {
|
||||
subDef.callback.apply( subDef.context, [envelope.data, envelope] );
|
||||
subDef.callback.call( subDef.context, envelope.data, envelope );
|
||||
subDef.onHandled();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue