Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is emitting on a symbol channel supported? #201

Closed
bcherny opened this issue Jan 20, 2017 · 5 comments · Fixed by #256
Closed

Is emitting on a symbol channel supported? #201

bcherny opened this issue Jan 20, 2017 · 5 comments · Fixed by #256

Comments

@bcherny
Copy link

bcherny commented Jan 20, 2017

const emitter = new EventEmitter2
const CHANNEL = Symbol('MyChannel')
emitter.emit(CHANNEL, 'foo')
@RangerMauve
Copy link
Contributor

This hasn't actually been tested before. My gut feeling is that it won't work nicely if you have wildcards enabled since the event string gets split up by separators and turned into a tree (which won't work with Symbol as it's not a string type).

@bcherny
Copy link
Author

bcherny commented Jan 20, 2017

That's what I figured too. Would you be interested in a PR to support Symbols, or is it beyond the scope of this lib?

@RangerMauve
Copy link
Contributor

If it didn't hurt performance, I could see it being a useful addition. Though I don't know if it'd really be worth bringing everything else in if all you want is an event emitter that uses symbols.

@bcherny
Copy link
Author

bcherny commented Jan 20, 2017

I wonder if you could model nested/wildcard channels with Symbols too:

import { EventEmitter2, Any } from 'eventemitter2'

const A = Symbol('A')
const B = Symbol('B')

const emitter = new EventEmitter2
emitter.on(A, () => {})
emitter.on([A, B], () => {})
emitter.on([A, Any], () => {})

@RangerMauve
Copy link
Contributor

Yeah, at that point I'd probably suggest making a separate symbol-based version. It should be easy enough to create a tree using an array of symbols and use that for looking up listeners.

DigitalBrainJS added a commit to DigitalBrainJS/EventEmitter2 that referenced this issue Apr 17, 2020
…wildcard events;

Optimize recursivelyGarbageCollect function;
DigitalBrainJS added a commit that referenced this issue May 3, 2020
Closes #251, Closes #162, Closes #201 listenTo, stopListening, hasListeners features, Symbol events support, this.event normalization & ReadMe improvements
@DigitalBrainJS DigitalBrainJS linked a pull request May 4, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants