new_widget_rendered event is published w/o reference to widget #42

Closed
valentinzberea opened this Issue Dec 20, 2012 · 5 comments

Comments

Projects
None yet
2 participants
Contributor

valentinzberea commented Dec 20, 2012

new_widget_rendered event is published only with reference to widget_id and widget_name

Why not pass the widget instance as this?

CC @aismail @skidding @topliceanu

Contributor

aismail commented Dec 20, 2012

When do you need it? I want to discourage binding reference between objects
because it makes garbage collection a lot harder.

Contributor

valentinzberea commented Dec 20, 2012

When testing a widget I subscribed to new_widget_rendered.
The event triggered correctly and I received the widget_id but loader.widgets didn't included it.

I will try to isolate the behaviour occurring in tests.

Contributor

aismail commented Dec 20, 2012

Maybe we're trying to hide another bug with this. Let's figure out why it
wasn't in loader.widgets in the first place.

Contributor

valentinzberea commented Mar 4, 2013

I will remove my workaround fix. First let's fix the root cause.

Description:

  1. When new_widget_rendered event is published for a widget_id you will see that loader.widgets[widget_id] is undefined

What is happening?

  1. Widget is injected

  2. widget_starter.loadWidget

  3. loader.load_widget

    load_widget: (name, id, params) ->
        path = loader.widget_path(name)
        callback = => loader.instantiate_widget(name, id, params)
        loader.load_module(path, callback, false)
  4. loader.instantiate_widget

    loader.widgets[id] = Utils.createModuleInstance(Module, params, tpl)
  5. Utils.createModuleInstance will call the widget constructor. widget/widget.coffee:

    constructor: (params, template = null) ->
        ...         
        @announceNewWidget()
    announceNewWidget: ->
    message = {
        name: @params['name']
        widget: @
        subscribed_channels: @_getTranslatedSubscribedChannels()
    }
    pipe = loader.get_module('pubsub')
    pipe.publish('/new_widget', message)
  6. Datasource listens to new_widget in datasource/datasource.coffee

  7. _bindWidgetToRelationalChannel is happening and if data is already fetched the widget method will be called.

  8. That one will trigger a render_layout

  9. new_widget_rendered is published

  10. widget constructor returns the instance for step 4. above

@valentinzberea valentinzberea added a commit that referenced this issue Mar 5, 2013

@valentinzberea valentinzberea fixed pubsub all + tests #42
Signed-off-by: Valentin Zberea <valentin.zberea@gmail.com>
96082ff

@valentinzberea valentinzberea added a commit that referenced this issue Mar 5, 2013

@valentinzberea valentinzberea fixed pubsubsub all event #42
Signed-off-by: Valentin Zberea <valentin.zberea@gmail.com>
d4293c9

@valentinzberea valentinzberea added a commit that referenced this issue Mar 5, 2013

@valentinzberea valentinzberea make pubsub publish events async #42
Signed-off-by: Valentin Zberea <valentin.zberea@gmail.com>
6a55371
Contributor

valentinzberea commented Dec 18, 2013

I am not pursuing this anymore. new_widget_rendered event offers enough info without exposing the widget instance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment