AugmentedDesignLab/botprint2 — pull request #19 by linzhp (2012-07-18 06:26:32+00:00)
Title: Bindable app

What I did in this pull request can be read from the commit log, but you'd better not read the diff commit by commit.

To date and in foreseeable future, we only need two event buses at a place: a local event bus and a global event bus. So I made a Bindable object (current Botprint, but it can be a dedicated Bindable object), holding the global event bus, and each view hold a local event bus, shared with its handlers. So instead of passing an global event bus around, I pass the global Bindable object (named app) around. Now event buses are totally transparent to controllers and views.

```JavaScript
// To communicate with other handlers
app.bind(ApplicationEvents.someEvent, someHandler);
app.trigger(ApplicationEvents.someEvent);

// To communicate with its own handlers
self.bind(UserEvents.someOtherEvent, someOtherHandler);
self.trigger(UserEvents.someOtherEvent);
```

I find this style clean and foolproof, with minimal modification to the original design.