-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat(context): improve context listener and events #4451
Conversation
a74170f
to
ee87f36
Compare
} | ||
this._parentEventListeners = undefined; | ||
if (this._parent && this.parentEventListener) { | ||
this._parent.removeListener('bind', this.parentEventListener); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old code removes all the listeners, any reason why only moves the bind and unbind now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old code uses a map for registered listeners. With this PR, only one function is used on bind/unbind events.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for creating this smaller pull request, it makes it much easier to review the changes and iterate on the best design & implementation 🙇
ee87f36
to
d3e927f
Compare
@bajtos Your comments have been addressed. PTAL. |
d3e927f
to
e3de3bf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Please get at least one more person to review & approve this new version.
} | ||
this.emit('bind', binding, this); | ||
this.emitEvent('bind', {binding, context: this, type: 'bind'}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can emitEvent
read the event name from event.type
?
this.emitEvent('bind', {binding, context: this, type: 'bind'}); | |
this.emitEvent({binding, context: this, type: 'bind'}); |
…ling BREAKING CHANGE: Context events are now emitted as `ContextEvent` objects instead of positional arguments. Context listener functions must switch from the old style to new style as follows: 1. Old style ```ts ctx.on('bind', (binding, context) => { // ... }); ``` 2. New style ```ts ctx.on('bind', (event: ContextEvent) => { // ... }); ``` Or: ```ts ctx.on('bind', ({binding, context, type}) => { // ... }); ```
e3de3bf
to
c5cd690
Compare
Spin-off from #4377
ContextEventListener
interfacemaxListeners
toInfinity
by defaultChecklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated👉 Check out how to submit a PR 👈