← Back to team overview

launchpad-dev team mailing list archive

Re: YUI sandboxes, event propagation and global namespaces

 

On Mon, 30 Jan 2012, Richard Harding wrote:

> On Mon, 30 Jan 2012, Ian Booth wrote:
>
> > Hello
> ...
> > 1. Event propagation across YUI instances
> >
> > When subscribing to events which are to be broadcast across instances,
> > here's how to do it:
> >
> > // In the subscribing instance...
> > Y.Global.on('event_name', function(e) {
> >     // code goes here
> > });
> >
> > To get the event to fire and be correctly broadcast, we first need to
> > publish it using the correct parameters:
> >
> > // In the publishing instance....
> > Y.publish(
> >     'event_name',
> >     {broadcast: 2,
> >      emitFacade: true
> >     }
> > );
>
> Ian, is this just because the events are fired and listened to off the Y
> instance? Did you see if these events were fired with respect to a DOM
> element do they still suffer the YUI() sandboxing issue?

I was too curious so I ran a series of tests. It didn't make sense or it
seemed we'd always be running into this.

So I've pasted a series of tests here:
http://paste.mitechie.com/show/523/

Basically yep, you're right. Two independant YUI() blocks cannot talk
across each other for events or the Y.XXX namespace.

The reason we don't typically hit this is that we don't tend to have these
blocks talk to each other. They always include some modules of application
code we write.

The tests show that as soon as you move one half of the code into a YUI
module and define something that the other block can add to it's use()
list, things work. Their namespaces are brought together. Events work, the
Y.xxx namespace is up to date, etc.

So now knowing that in order for two blocks of code to communicate events
between each other, the key is to get the blocks into the same YUI() block.
In this case, it would seem like adding lp.bugs.bugtask_index as a use() of
the YUI() block in the form-picker-macros would allow the events to be
fired and shared between setup_bugtask_table and the setup code in the TAL.

Does that make sense Ian?

Thanks Ian for chasing this down and teaching us a bit more about how
things are working in the current code and some of challenges we'll be
facing in our move to better practices.

--

Rick Harding

Launchpad Developer
https://launchpad.net/~rharding
@mitechie


Follow ups

References