Raynos / dom-delegator

Decorate elements with delegated events
MIT License
58 stars 16 forks source link

Allow a list of custom events to be passed in as part of opts #16

Open aghassemi opened 9 years ago

aghassemi commented 9 years ago

It would be nice to be able to extend the list of common events that are hard-coded here with just passing a list of custom events as part of the opts.

neonstalwart commented 9 years ago

@aghassemi just wanted to check that you're aware you can do:

var delegator = new Delegator(),
    customEvents = [ 'foo', 'bar', 'baz' ];

customEvents.forEach(function (event) {
    delegator.listenTo(event);
});

i realize you're asking for more convenience than that but just wanted to make sure you know that is an option for now.

aghassemi commented 9 years ago

I am sort of doing this but the issue is I don't have direct access to the delegator instance that is created by Mercury. But Mercury does let me pass options to delegator constructor in the function app() (see https://github.com/Raynos/mercury/blob/master/index.js) so it would be nice to be able to pass them as part of opts.

My work around relies on the fact that delegator is a singleton and cached, so even-though I don't have access to the delegator instance created by Mercury, doing mercury.Delegator({defaultEvents: false}).listenTo(customEvent) happens to work due to singleton nature of delegator.

neonstalwart commented 9 years ago

yeah. that's exactly part of why it's a singleton - what you're doing is the way it's expected that you should do it.

aghassemi commented 9 years ago

Sounds good. Thanks for clarifying.

Raynos commented 9 years ago

@aghassemi the delegator is a globally cached singleton for this and other reasons.

That's never going to change.