By now you know that I’m a fan of pub-sub / event aggregators, whether it’s .NET / Winforms or Backbone or whatever. For the last 3 weeks working on this WinJS / WinRT app with the Microsoft P&P group, I’ve had this thought that I want to do the same thing in WinJS / WinRT apps. Only I couldn’t figure out how. @Bennage and I had several discussions on this and decided to look in to it later. Well today was “later” apparently, and thanks to the Chris Tavares I found these wonderful little nuggets of awesome:
Of course this is only an application level event aggregator. If I want to use localized / sub-application / module event aggregators, I need to find another way to make that happen. I have some leads on this, but haven’t had a chance to work on them yet. I have hope, though, and this is yet another reason that I really like working on WinJS apps.
Derick Bailey is a Developer Advocate for Kendo UI, a problem solver (and creator? :P ), software developer, screecaster, writer, blogger, speaker and technology leader in central Texas (north of Austin). He has been a professional software developer since the late 90's, and has been writing code since the late 80's.
Find me on twitter:
@derickbailey,
@mutedsolutions,
@backbonejsclass
Find me on the web:
WatchMeCode (screencasts),
Kendo UI blog, MarionetteJS, My Github profile,
On Google+.
Since you are already a big Backbone user, why wouldn’t you just use Backbone events? Did you have a constraint where you couldn’t use third party libraries?
http://mutedsolutions.com Derick Bailey
In the current project, our goal is to create a sample app that provides core guidance on how to build a WinJS app with as few external libraries as possible. The app itself doesn’t use anything 3rd party – only the test suite does.
In the future (after this project), I want to explore what WinJS + Backbone would look like and see if that would really bring any value to the table, where it would bring value, etc. Of course all of that depends on how much free time I have :)
Dave Stibrany
Hey Im also a fan of using pub/sub. Whats the advantage of having localized event aggregators rather then just one at the app level. Is it just to avoid event name collisions?
http://mutedsolutions.com Derick Bailey
name collision is one reason, but a small one. more importantly: reduce dependencies between objects that can legitimately know about each other because of some other relationship they already have, and reduce memory leaks in some situations by allowing the event binding / triggering to be garbage collected with the objects that trigger and respond to the events. lastly, the semantics introduced with localized pub/sub allows the app to be modularized in a more re-usable manner. you can take a module with you, without being forced to take the global dependency with you.