How to handle your own events?

Hello!

I have a problem here, I want to handle my own events.
In other words I want to set some event handlers with defaults.
I've tried this:
events: {
     onSetupItem: "setupItem",
    onChildAdd: "ChildAdd",
    onChildChange: "ChildChange",
    onChildRemove: "ChildRemove",
    onChildMove: "ChildMove"
},
and this:
handlers: {
     onSetupItem: "setupItem",
    onChildAdd: "ChildAdd",
    onChildChange: "ChildChange",
    onChildRemove: "ChildRemove",
    onChildMove: "ChildMove"
},
with no avail.

Comments

  • Generally, you define your events in your kind and listen for them in another kind that contains it. The containing kind usually has the handlers you defined (either in the handlers block or on your declared kind in the components block).

    Where is that handlers block?
  • The handler block is above the events block, however the order shouldn't matter from what I know. They are both in the same kind.
  • edited May 2013
    That's what I'm saying. You don't typically put them in the same kind. The events are defined in your custom/extended kind and the handlers are in the kind that owns/declares it.

    Also, you generally DON'T specify a value in the events block. If you do, the system will look for that function in the owner to run when you fire that event. If you leave them blank and the handlers block in the same kind, that SHOULD catch the event in itself...I think.
  • As Dave mentioned, while you can include a handlers block in your kind that sends out the event, it's not typically the way to do it. I'm not quite sure why you've chosen that as your way of doing it, but here's a fiddle demonstrating how to do that: http://jsfiddle.net/arthurthornton/JqWJ7/

    Another way you could do this is like so, where you would include the code where you call doYourEventName: http://jsfiddle.net/arthurthornton/JqWJ7/1/
  • Thanks!
    The first solution was what I was trying to do but didn't work, the second does work once you change line 8 to:
    if (this.doSomething() === true) return; and remember to return true from all handlers.
Sign In or Register to comment.