Subviews calling methods

17 views
Skip to first unread message

Shell (Aridhia Informatics)

unread,
Jul 3, 2013, 8:04:43 AM7/3/13
to choru...@googlegroups.com
Hi guys,

We're breaking a rather complex page into subviews. View 'A' contains subview 'B' and 'C'. View B generates a string which needs to be passed to view C for display purposes. While we have several 'dirty' ways that would probably work, we think there must be an elegant way / best practice for passing data from one subview to another. Any suggestions?

Shell

Shell (Aridhia Informatics)

unread,
Jul 3, 2013, 8:39:20 AM7/3/13
to choru...@googlegroups.com
This is what we've done to get it working, whether or not it's "best practice" or not remains to be seen :)

view b)

chorus.pageEvents.broadcast( "ourEvent", { message: "foo" } );


view c)

this.subscribePageEvent("ourEvent", this.handleThatEvent );

...

handleThatEvent
: function( param ) {
    console
.log( param.message ); // => "foo"
}

Charles Hansen

unread,
Jul 3, 2013, 12:58:00 PM7/3/13
to choru...@googlegroups.com
Hi Shell,

Normally when we see a pattern like this, it means we should use a shared object (possibly a backbone model) to generate and hold that string.  If this doesn't work, sometimes we will use page events like your example.  Sometimes we will include a pointer to B in C so that C can ask directly for the string.  The shared object is certainly the cleanest method.

Charles & Gavin


--
You received this message because you are subscribed to the Google Groups "chorus-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chorus-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Shell (Aridhia Informatics)

unread,
Jul 4, 2013, 6:38:33 AM7/4/13
to choru...@googlegroups.com
Hi Charles,

Thanks. We've decided to keep our messaging pattern - while not ideal, we can't really move the data or data generation into a model as it's a 3rd-party jquery plug-in that's the culprit...

S.
Reply all
Reply to author
Forward
0 new messages