Add listeners to existing Signals instance.

How would one go about adding additional event listeners to an existing enyo.Signals instance?

The following would probably work:
enyo.kind({
  name: "myKind",
  components: [{
    kind: "enyo.Signals",
    "MessageA": "onMessageA"
  }],
  onMessageA: function() {
    // some reaction
  }
});
enyo.kind({
  name: "mySubKind",
  kind: "myKind",
  components: [{
    kind: "enyo.Signals",
    "MessageB": "onMessageB"
  }],
  onMessageB: function() {
    // some reaction
  }
});
But then I would have 2 enyo.Signals instances where (afaik) only one would suffice.

Comments

  • Signals is created as a component like any other so, once named, can be referenced by the $ hash. The event dispatcher discovers the handler by a matching name on the instance. So, together, you can set this.$.signals.MessageB = 'onMessageB'; assuming you either named the Signals instance on myKind as signals or it were the first Signals instance on the kind (pretty likely but I'd still recommend an explicit name).
  • Allright, that explains a lot :smiley: that's actually super simple. Awesome!
Sign In or Register to comment.