Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : Controller Communication ways.

$
0
0
There are two good ways to allow Controls to communicate with one another.

Events
Controllers can emit events that other Controllers respond to and handle. This approach is nice because the Controller emitting the event doesn't have to know who will respond. The drawback is that any other Controller must be higher up in the hierarchy of the DOM for things to work nicely. Two Controllers on sibling elements would require that the Controllers bind to event outside of their element.

State (Observe/routing)
The best way to communicate is having an Observe that represents the client state and passing that into every Controller. Each Controller would bind to the Observe's change events and handle any changes in state that occur. This video explains this concept very well.

You can also use routes which is just an Observe whose underlying data is the window.location.hash. This can be used in conjunction with, or instead of a clientstate Observe.

If you are just starting your project, take a look at CanJS. It will be the MVC core of JMVC 3.3 which is days away from being released.

Viewing all articles
Browse latest Browse all 3491

Trending Articles