Child context and defering

23 views
Skip to first unread message

Gehan Gonsalkorale

unread,
Sep 30, 2013, 1:13:51 PM9/30/13
to cuj...@googlegroups.com
Hey guys!

When you create a child context using the wire plugin, then it's a child context and you can access components in the parent context - which is great (e.g. for having a user/session at the top level.

However when you create the child context using defer: true, and so have to call that wire fn() later, this is no longer a child context but just a new context with no parent! This is a bit annoying - is there any reason for this difference? I'm sure there is a way around it but was this decision conscious or is it just a side effect of how defer works? Also what would be the easiest way to get the parent context?

If you're wondering why, its simply to have a different spec for different areas of the site and create/destroy them as needed :)

Gehan

Brian Cavalier

unread,
Sep 30, 2013, 9:35:52 PM9/30/13
to cuj...@googlegroups.com
Hey Gehan,

The deferred child should still be a child--it should still have a parent, and not be detached.  The way you're using it (create/destroy as needed) is the perfect use case for wire defer (I'm pretty sure I created it because I needed to do exactly that!).

So, if you're seeing it be detached, it could be a bug.  Do you have a simple case that shows the problem?  I took a quick look at the code, and it seems right (https://github.com/cujojs/wire/blob/dev/lib/plugin/wirePlugin.js#L81-L97).  I also just added a test case to verify:


Maybe there is some edge case that I'm not covering though, so if you have an example, post it and we can work through it to see what is going on.

Gehan Gonsalkorale

unread,
Oct 1, 2013, 3:15:45 AM10/1/13
to cuj...@googlegroups.com
Yes you are right! I thought it didn't happen for some reason. I just tested our code and it works as intended! I did think it odd that it wouldn't do this - well turns out it does. Thanks!


--
You received this message because you are subscribed to a topic in the Google Groups "cujojs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cujojs/35IYu1S-9oE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cujojs+un...@googlegroups.com.
To post to this group, send email to cuj...@googlegroups.com.
Visit this group at http://groups.google.com/group/cujojs.
To view this discussion on the web visit https://groups.google.com/d/msgid/cujojs/9c948b4b-29ff-4093-ac32-7819ed592757%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Brian Cavalier

unread,
Oct 1, 2013, 11:06:31 AM10/1/13
to cuj...@googlegroups.com
Woohoo :)  No problem at all.
Reply all
Reply to author
Forward
0 new messages