Knockout AMD & Postal.js

221 Views Asked by At

I'm using knockout components and postal.js for the communication between the components.

I have registered two components, A and B. When the page loads, I want A to send a message to B. I have this:

define(['postal',''text!./templateA.html''], function (postal, html) {
    function ComponentA() {
        postal.publish({
            channel: "channel1",
            topic: "topic1",
            data: "Hello!"
        });
    }    
    return { viewModel: ComponentA, template: html };
}

...

define(['postal',''text!./templateB.html''], function (postal, html) {
    function ComponentB() {
        postal.subscribe({
            channel: "channel1",
            topic: "topic1",
            callback: doSomething
        });
    }
    return { viewModel: ComponentB, template: html };
}

The problem is that sometimes component A sends the message before component B is loaded, and therefore, ready to receive the message. So the message is lost and the action in component B is not executed.

EDIT:

What's the best way to control the order how components are loaded?

0

There are 0 best solutions below