Closed aismail closed 11 years ago
CC @uberVU/mozaic-core-commiters
I've changed my mind and will move APIs for global channel management in channels_utils.coffee. No need to create yet a new file just for this.
I agree that a widget shouldn't have knowledge of its ancestors, this breaks encapsulations. Parents know of children, children don't know of parents. One single global namespace for eternal channels would be better
I would make a different approach (haven't checked the code to see if it's possible). Passing global/ channels also implies extra lines of code in parent widgets. It'd integrate this in the widget starter somehow or even in the widget itself. A widget has a list of subscribed_channels. It goes through each of them and looks for the corresponding channel in its params.channels, if not found, looks in the global.channels, if not even there, throw error for channel mismatch.
@skidding - you mean you can create an eternal channel from anywhere and access it from anywhere? If yes, I think you can do that with the current implementation - only that by default some eternal channels are created from our custom ApplicationController.
I don't like "defaulting" to the global channels because the only decent chance to match channels is by name. And it forces us to write widgets who know about the global state, instead of deriving meaningful internal names for their own channels.
Appart from this, please check the PR and lmk what you think!
hub pull-request
!
Need
In ubervu.com Single Page App we have a custom ApplicationController that creates default channels available throughout the lifecycle of the application. It's becoming really cumbersome to propagate these global channels (a few of them, really) to widget nested deeply within.
We need a quick and easy way for widgets to subscribe to these channels.
Deliverables
Then datasource will check the id of the channels it receives and transforms them for all operations.
Notes
This is a long-standing request but it must be handled with care: we must not break Mozaic's best feature, forcing widgets to be reusable through the programming model. Therefore, we need to check that widgets don't subscribe themselves to global channels.
Also, I've considered including the feature discussed with @skidding some time ago to subscribe to channels created by ancestors of a widget. However, I think this would require widgets to make assumptions about the context in which they are injected from, limiting reusability.