Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Expand the Evented.on() API #33

Closed
kitsonk opened this issue May 25, 2016 · 3 comments
Closed

Expand the Evented.on() API #33

kitsonk opened this issue May 25, 2016 · 3 comments
Milestone

Comments

@kitsonk
Copy link
Member

kitsonk commented May 25, 2016

To allow the listener to be an array of listeners as well as accept a map/hash of listeners.

@kitsonk kitsonk added this to the 2016.05 milestone May 25, 2016
@kfranqueiro
Copy link
Member

Kinda curious what the use case for hashes in particular is?

@kitsonk
Copy link
Member Author

kitsonk commented May 25, 2016

When you have a lot of listeners to supply for different events. In particular it came up in the app factory, when configuring up certain instances, it is often easier to supply a map/hash, which is especially functional when combined with the terse method expression in object literals. It is also actually supported on creation already:

/* already works */
const evented = createEvented({
  listeners: {
    foo(evt) { /* handle event */ }
  }
});

/* also this would work with the change */
evented.on({
  bar(evt) { /* handle event */ },
  qat(evt) { /* handle event */ }
});

As a consumer, you can register for all the events you care about and get a single handle return which would disconnect those listeners.

You can also use additional ES6 syntax to make it even more concise (and more easy to read what you are doing):

function foo(evt: CustomEvent) { /* do something */ }
function bar(evt: CustomEvent) { /* do something */ }

evented.on({ foo, bar });

@kfranqueiro
Copy link
Member

Oh, I didn't think about it enabling shorthand with ES6 syntax. But yeah, I've at least had a couple of occasions in the past where I've wanted a handle for a group of events and did that myself for an array.

kitsonk added a commit that referenced this issue May 25, 2016
`Evented.on()` now takes arrays of listeners as well as map/hash values to describe the event
types and listeners.

Fixes #33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants