uberVU / mozaic

JS Framework for building SPA
http://ubervu.github.com/mozaic/
26 stars 17 forks source link

Devise way for widgets to subscribe to "global" channels that are created by the application controller #95

Closed aismail closed 11 years ago

aismail commented 11 years ago

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


class GlobalChannels

    create: (alias, type, params) ->
        ###
             Creates a global channel of the given type with the given params under the
             given alias. Global channels will have the "eternal" flag on - a.k.a. they will
             never be garbage collected even though there are no widgets subscribed to 
             them.

             The channel_alias -> channel_id mapping should be stored in the Mozaic
             global object. The result of the function is the channel id of the newly created
             channel because we might need to use it right away.
        ###
        return

    get: (alias) ->
        ###
            Retrieve a global channel id for a given alias, or return None if no channel with
            that alias was found.

            We should discourage widgets from using this API in order to increase their
            reusability. Therefore, this will be called only by the DataSource.
        ####

Utils.inject('widget',
    params:
        channels:
            '/social_profiles': 'GLOBAL/social_profiles_for_posting' # social_profiles_for_posting is the alias of the global channel

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,

ovidiuch commented 11 years ago

This should have at least a commit reference to the code pulled for this issue...