Parametrized events in Controllers

11 views
Skip to first unread message

PatrickR

unread,
Oct 5, 2010, 11:57:06 AM10/5/10
to JavaScriptMVC
Hi,

I pretty much want to to what is described in this discussion:
http://groups.google.com/group/javascriptmvc/browse_thread/thread/8a63db20208dcfdd/d3ffe95160e26c88?lnk=gst&q=parameterized+action+names+#d3ffe95160e26c88

i.e. have parametrized event listeners. From the above I gather that
this has been tried or maybe even implemented. Is it?

I've tried something like the following without success:

$.Controller.extend('Foo',{},
{
_topics: ['bar','bim'],
'myevent.{_topics[1]}.** subscribe': function(topic, data) {
// do stuff
}
});

The main reason behind wanting to do this is that I'd like all topics
namespaced and available through a separate class. This would makes
documentation better and enables tab completion in good IDEs. So my
events would actually look like
'{MyEventClass.SomeEventTopic}.**': ... Maybe there is a better way to
achieve that?

Thanks,
/Patrick

Justin Meyer

unread,
Oct 5, 2010, 12:04:39 PM10/5/10
to javasc...@googlegroups.com
Parameterized only happens with the options (2nd param to a controller)

You could so it like:

$.Controller.extend("Foo",{
  defaults: {
    namespace : MyEventClass.Namespace
  } 
},{
  "{namespace}.created subscribe" : function( ..) { ... }
})

Whatever is in MyEventClass.Namespace when the class is created would be {namspace} in the action.  You could overwrite this when creating controller instances:

$('.bar').foo({namespace: "somethingElse"})




Justin Meyer

Jupiter Consulting
\Development\Training\Support
847-924-6039
justin...@gmail.com



--
You received this message because you are subscribed to the Google Groups "JavaScriptMVC" group.
To post to this group, send email to javasc...@googlegroups.com.
To unsubscribe from this group, send email to javascriptmv...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javascriptmvc?hl=en.


PatrickR

unread,
Oct 8, 2010, 3:52:56 AM10/8/10
to JavaScriptMVC
Great, thanks!

/Patrick

On Oct 5, 6:04 pm, Justin Meyer <justinbme...@gmail.com> wrote:
> Parameterized only happens with the options (2nd param to a controller)
>
> You could so it like:
>
> $.Controller.extend("Foo",{
>   defaults: {
>     namespace : MyEventClass.Namespace
>   }},{
>
>   "{namespace}.created subscribe" : function( ..) { ... }
>
> })
>
> Whatever is in MyEventClass.Namespace when the class is created would be
> {namspace} in the action.  You could overwrite this when creating controller
> instances:
>
> $('.bar').foo({namespace: "somethingElse"})
>
> Justin Meyer
>
> Jupiter Consulting
> \Development\Training\Support
> 847-924-6039
> justinbme...@gmail.com
>
>
>
> On Tue, Oct 5, 2010 at 10:57 AM, PatrickR <patrick.run...@gmail.com> wrote:
> > Hi,
>
> > I pretty much want to to what is described in this discussion:
>
> >http://groups.google.com/group/javascriptmvc/browse_thread/thread/8a6...
>
> > i.e. have parametrized event listeners. From the above I gather that
> > this has been tried or maybe even implemented. Is it?
>
> > I've tried something like the following without success:
>
> > $.Controller.extend('Foo',{},
> > {
> >   _topics: ['bar','bim'],
> >    'myevent.{_topics[1]}.** subscribe': function(topic, data) {
> >    // do stuff
> >   }
> > });
>
> > The main reason behind wanting to do this is that I'd like all topics
> > namespaced and available through a separate class. This would makes
> > documentation better and enables tab completion in good IDEs. So my
> > events would actually look like
> > '{MyEventClass.SomeEventTopic}.**': ... Maybe there is a better way to
> > achieve that?
>
> > Thanks,
> > /Patrick
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "JavaScriptMVC" group.
> > To post to this group, send email to javasc...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > javascriptmv...@googlegroups.com<javascriptmvc%2Bunsubscribe@goog legroups.com>
> > .
Reply all
Reply to author
Forward
0 new messages