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(platform-browser): Expose EventManagerPlugin in the public api #49969
Conversation
194df57
to
f0e54d7
Compare
f0e54d7
to
ba4972d
Compare
ba4972d
to
4a638c3
Compare
Can I get the aio: preview ? 😊 |
9a97166
to
3fcd5c7
Compare
aio/content/examples/custom-events/src/app/stop-event-plugin.ts
Outdated
Show resolved
Hide resolved
e35bca5
to
dd607de
Compare
export abstract class EventManagerPlugin { | ||
abstract addEventListener(element: HTMLElement, eventName: string, handler: (event: Event) => void): Function; | ||
// (undocumented) | ||
manager: EventManager; |
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.
I don't feel like the EventManager
setting this property is a particularly good API. I understand that it's attempting to prevent a situation where the Zone
is different but practically speaking, I don't think this ever happens. I would rather this be exposed as an interface that does not include manager
.
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.
Great idea, that property bothered me also !
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.
Without that property, the example doesn't work, as well as the broader concept of unintrusive plugins that do their part and delegate further handling back to the manager which is heavily used by @tinkoff/ng-event-plugins.
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.
They only don't work because of the way things are implemented currently. The could be refactored to work without the property being assigned by the EventManager
itself.
That said, this was more of a discussion point because I don't necessarily think it's worth the churn to do this as a breaking change.
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 problem of accessing the manager can be solved by injecting it !
export class StopEventPlugin {
constructor(private injector: Injector) {}
supports(event: string): boolean {
return event.endsWith('.stop');
}
addEventListener(element: HTMLElement, eventName: string, handler: (event: Event) => void): Function {
const eventWrapper = (event: Event) => {
event.stopPropagation();
handler(event);
};
// striping the stop modifier from the event name;
const nonModifiedEventName = eventName.replace(/\.stop$/, '');
const manager = this.injector.get(EventManager);
return manager.addEventListener(element, nonModifiedEventName, eventWrapper);
}
}
Or we could run addEventListener
in an injection context in the manager :
addEventListener(element: HTMLElement, eventName: string, handler: Function): Function {
const plugin = this._findPluginFor(eventName);
return runInInjectionContext(this.injector, () => plugin.addEventListener(element, eventName, handler as (event: Event) => void));
}
What do you think ?
Should we revert the breaking change or suggest to inject the manager if it's needed ?
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.
Personally, I don't think switching from property assignment by EventManager
to the entire Injector
to avoid cyclic dependency is much better. Sounds like for plugins to have direct access to the manager is reasonable.
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.
Sounds like for plugins to have direct access to the manager is reasonable.
Having access to the manager isn't really the issue, but rather the awkwardness of having a public API where the some other service assigns a value to a user's publicly writable property after the service is created.
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.
Maybe use the same approach control value accessors have and add registerManager(manager: EventManager): void
?
913a9d0
to
c7819f6
Compare
@JeanMeche Can you separate this in to two PRs? One that simply adds the |
c7819f6
to
09dd296
Compare
@atscott I've reduced the scope of the PR to adding Do you have any clue why |
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.
reviewed-for: public-api
Deployed aio for 2c61afe to: https://ng-dev-previews-fw--pr-angular-angular-49969-8pvqqo9w.web.app Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt. |
@josephperrott I have a tooling question for you. I was trying to start a TGP, but g3sync fails with a patch conflict (albeit a very simple one). Is it possible to update the patch for my g3sync presubmit, without actually committing the patch update? |
@dylhunn replying offline as this is a g3 specific item. |
I will run a TGP on this CL tonight. |
babdbed
to
e2af26a
Compare
e2af26a
to
ab1d8c7
Compare
The exposed type of the `EVENT_MANAGER_PLUGINS` token should be in the public API.
ab1d8c7
to
2c61afe
Compare
TGP passed. |
This PR was merged into the repository by commit c5daa6c. |
angular#49969) The exposed type of the `EVENT_MANAGER_PLUGINS` token should be in the public API. PR Close angular#49969
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
angular#49969) The exposed type of the `EVENT_MANAGER_PLUGINS` token should be in the public API. PR Close angular#49969
This commit exposes the
EventManagerPlugin
abstract class to the public API.It provides a documentation with a usecase and a basic implementation describing the possibilities
Rationale for opening to the public API :
EVENT_MANAGER_PLUGINS
token is already publicPR Type
What kind of change does this PR introduce?
Does this PR introduce a breaking change?