postaljs / postal.when Goto Github PK
View Code? Open in Web Editor NEWpostal.js plugin that enables message-bus-based deferred style async behavior
Home Page: http://freshbrewedcode.com/jimcowart
postal.js plugin that enables message-bus-based deferred style async behavior
Home Page: http://freshbrewedcode.com/jimcowart
Hello,
I've just discovered that publishing messages to a when
array of channelDefs
will fail to cause the when
callback to be called if the messages do not have a data
property. I'm having to do this:
postal.publish({ channel: 'c', topic: 't', data: {} }); // <- empty data property
I'm not suggesting that the data
property's value must be an empty plain object, only that it must be present. If I remove the data
property, the when
callback never gets called.
I don't think this is appropriate. It's not always the case that the message payloads are of interest. Meaningfulness might actually simply be that all of the messages were published and received [within the timeout interval], without regard for the payloads.
Please advise.
Thank you!
When running the example using postal.when-0.2.0, postal-0.10.1, conduit-0.3.2, lodash-2.4.1-compat, in Chrome v36, I received the following error:
"You can only make functions into Conduits." from conduit.js
By adding an explicit, empty callback function to each of the channels, the issue appears to have gone away.
postal.when([
{ channel: "ChannelA", topic: "topic.on.channel.a", callback: function() {} },
{ channel: "ChannelB", topic: "topic.on.channel.b", callback: function() {} },
{ channel: "ChannelC", topic: "topic.on.channel.c", callback: function() {} },
{ channel: "ChannelD", topic: "topic.on.channel.d", callback: function() {} },
], function(a, b, c, d){
_.each(arguments, function(x) {
$('body').append("<div>" + x + "</div>");
});
});
postal.publish( { channel: "ChannelD", topic: "topic.on.channel.d", data: "And it's testable!" } );
postal.publish( { channel: "ChannelB", topic: "topic.on.channel.b", data: "Deferred behavior!" } );
postal.publish( { channel: "ChannelA", topic: "topic.on.channel.a", data: "Hey look!" } );
postal.publish( { channel: "ChannelC", topic: "topic.on.channel.c", data: "Via message bus!" } );
Hopefully this help. Thanks for your hard work on postal.when. It's very helpful.
The lastest release also remove Conduitjs dependency.
You can install via the repo’s URL, of course.
Regular postal works great with require; if you publish on a channel from a dependency, the module depending on it receives that transmission through a subscription. I.E. if 'app/app' is defined like so:
define(['postal', 'postal.when'], function (postal) {
var app = postal;
return app;
});
Then, the following works:
requirejs(['app/app', 'app/homeBackgroundSlider'],
function ( app, homeBackgroundSlider) {
// homeBackgroundSlider sends homeBackgroundSlider.complete on the default channel
app.channel().subscribe('homeBackgroundSlider.complete', function() {
console.log('this works');
});
});
But this won't work:
requirejs(['app/app', 'app/homeBackgroundSlider'],
function ( app, homeBackgroundSlider) {
// homeBackgroundSlider sends homeBackgroundSlider.complete on the default channel
app.when([{topic: 'homeBackgroundSlider.complete'}], function() {
console.log('this doesn\'t work');
});
});
Now I've only started digging into postal.when, but my guess is that because 'app/homeBackgroundSlider' is included as a dependency, it actually executes before the module above, meaning that it publishes before the when statement listens. However, that it works using "vanilla" postal's subscribe means that perhaps this issue has to do with the postal.when code specifically. In fact, I had this issue elsewhere and created my own postal.when functionality in code, I just don't want to have to do that (makes postal.when useless in requireJS applications).
(using 0.9.0)
I've been using postal successfully for a while now, and I reach a point where I need the functionality in postal.when. But I haven't been able to get it to work in a browser using AMD.
The example given on GitHub for AMD doesn't seem plausible: 3 modules are required, but only two are defined in the function arguments. The example goes on to use "postal.when", but postal is never required (only its path is defined). And 'postal.when' is required, but the path is never defined, nor does it show up in the function arguments.
How, exactly, do we use postal.when under AMD and in a browser?
Thank you.
The last commit was 3 years ago, the repository has 4 issues opened and 3 pull request awaiting merge.
Is it abandoned?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.