Skip to content

Commit 0cb5031

Browse files
tbondwilkinsonatscott
authored andcommitted
refactor(core): Rename BaseDispatcher to Dispatcher. (angular#55721)
Rename `BaseDispatcher` to `Dispatcher` and `Dispatcher` to `LegacyDispatcher`. The `GlobalHandler` type and `stopPropagation` function needs to be left for now in dispatcher.ts as it was not exported previously from legacy_dispatcher.ts. PR Close angular#55721
1 parent 7187394 commit 0cb5031

File tree

10 files changed

+413
-393
lines changed

10 files changed

+413
-393
lines changed

goldens/public-api/core/primitives/event-dispatch/index.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,16 @@
55
```ts
66

77
// @public
8-
export class BaseDispatcher {
8+
export function bootstrapEarlyEventContract(field: string, container: HTMLElement, appId: string, eventTypes?: string[], captureEventTypes?: string[], earlyJsactionTracker?: EventContractTracker<EarlyJsactionDataContainer>): void;
9+
10+
// @public
11+
export class Dispatcher {
912
constructor(dispatchDelegate: (eventInfoWrapper: EventInfoWrapper) => void, { eventReplayer }?: {
1013
eventReplayer?: Replayer;
1114
});
1215
dispatch(eventInfo: EventInfo): void;
13-
queueEventInfoWrapper(eventInfoWrapper: EventInfoWrapper): void;
14-
scheduleEventReplay(): void;
1516
}
1617

17-
// @public
18-
export function bootstrapEarlyEventContract(field: string, container: HTMLElement, appId: string, eventTypes?: string[], captureEventTypes?: string[], earlyJsactionTracker?: EventContractTracker<EarlyJsactionDataContainer>): void;
19-
2018
// @public (undocumented)
2119
export interface EarlyJsactionDataContainer {
2220
// (undocumented)
@@ -33,12 +31,12 @@ export class EventContract implements UnrenamedEventContract {
3331
cleanUp(): void;
3432
// (undocumented)
3533
ecaacs?: (updateEventInfoForA11yClick: typeof a11yClickLib.updateEventInfoForA11yClick, preventDefaultForA11yClick: typeof a11yClickLib.preventDefaultForA11yClick, populateClickOnlyAction: typeof a11yClickLib.populateClickOnlyAction) => void;
36-
ecrd(dispatcher: Dispatcher, restriction: Restriction): void;
34+
ecrd(dispatcher: Dispatcher_2, restriction: Restriction): void;
3735
exportAddA11yClickSupport(): void;
3836
handler(eventType: string): EventHandler | undefined;
3937
// (undocumented)
4038
static MOUSE_SPECIAL_SUPPORT: boolean;
41-
registerDispatcher(dispatcher: Dispatcher, restriction: Restriction): void;
39+
registerDispatcher(dispatcher: Dispatcher_2, restriction: Restriction): void;
4240
replayEarlyEvents(earlyJsactionContainer?: EarlyJsactionDataContainer): void;
4341
}
4442

@@ -99,7 +97,7 @@ export class EventInfoWrapper {
9997
}
10098

10199
// @public
102-
export function registerDispatcher(eventContract: UnrenamedEventContract, dispatcher: BaseDispatcher): void;
100+
export function registerDispatcher(eventContract: UnrenamedEventContract, dispatcher: Dispatcher): void;
103101

104102
// (No @packageDocumentation comment for this package)
105103

packages/core/primitives/event-dispatch/README.md

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This can introduce a couple problems:
2020

2121
1. Server rendered applications will silently ignore user events that happen
2222
before the app hydrates and registers handlers
23-
23+
2424
```html
2525
<!-- Let's say this server-rendered page is streamed to the browser -->
2626
<body>
@@ -45,14 +45,14 @@ This can introduce a couple problems:
4545
2. Applications must eagerly load any possible handler that could be needed to
4646
handle user interactions, even if that handler is never invoked or even
4747
rendered on the page
48-
48+
4949
```html
5050
// This button is rarely clicked, but the code to show the dialog must be
5151
// loaded for every user
5252
<button type="button" (click)="showAdvancedOptionsDialog()">
5353
Advanced options
5454
</button>
55-
55+
5656
// Non-admins will never see this button, and yet they still have to load
5757
// this handler.
5858
@if (isAdmin) {
@@ -61,7 +61,7 @@ This can introduce a couple problems:
6161
</button>
6262
}
6363
```
64-
64+
6565
It's possible to write these handlers so that they will late-load their
6666
inner logic, but that's a manual, opt-in solution.
6767
@@ -114,13 +114,13 @@ valid-char = character - invalid-name-chars
114114
invalid-name-chars = ":" | ";" | "."
115115
```
116116
117-
- Omitting the event type and colon will default the binding to the `click`
118-
event (e.g.`jsaction="handleClick;hover:handleHover"`)
119-
- Both the event type and handler name can be the empty string (but make sure
120-
to keep the colon: `jsaction="change:;"`)
121-
- The `event-handler` is an arbitrary string that can store metadata needed to
122-
find the handler that handles the event. The user of JSAction can choose to
123-
define the semantics of the handler string however they like.
117+
- Omitting the event type and colon will default the binding to the `click`
118+
event (e.g.`jsaction="handleClick;hover:handleHover"`)
119+
- Both the event type and handler name can be the empty string (but make sure
120+
to keep the colon: `jsaction="change:;"`)
121+
- The `event-handler` is an arbitrary string that can store metadata needed to
122+
find the handler that handles the event. The user of JSAction can choose to
123+
define the semantics of the handler string however they like.
124124
125125
#### Example
126126
@@ -200,10 +200,8 @@ Finally, once your application is bootstrapped and ready to handle events,
200200
you'll need to create a `Dispatcher` and register it with the `EventContract`
201201
that has been queueing events.
202202

203-
<!-- TODO(b/337878694): Update this once the `BaseDispatcher` is renamed to be just `Dispatcher` -->
204-
205203
```javascript
206-
import {BaseDispatcher as Dispatcher, registerDispatcher} from '@angular/core/primitives/event-dispatch/src/base_dispatcher';
204+
import {Dispatcher, registerDispatcher} from '@angular/core/primitives/event-dispatch';
207205

208206
function handleEvent(eventInfoWrapper) {
209207
// eventInfoWrapper contains all the information about the event
@@ -246,16 +244,16 @@ some tradeoffs to doing this:
246244

247245
Pros of cleaning up event contract:
248246

249-
- Native handlers avoid the [quirks](#known-caveats) of JSAction dispatching
247+
- Native handlers avoid the [quirks](#known-caveats) of JSAction dispatching
250248

251249
Pros of keeping event contract:
252250

253-
- JSAction's event delegation drastically reduces the number of event
254-
listeners registered with the browser. In extreme cases, registering
255-
thousands of listeners in your app can be noticably slow.
256-
- There may be slight behavior differences when your event is dispatched via
257-
JSAction vs native event listeners. Always using JSAction dispatch keeps
258-
things consistent.
251+
- JSAction's event delegation drastically reduces the number of event
252+
listeners registered with the browser. In extreme cases, registering
253+
thousands of listeners in your app can be noticably slow.
254+
- There may be slight behavior differences when your event is dispatched via
255+
JSAction vs native event listeners. Always using JSAction dispatch keeps
256+
things consistent.
259257

260258
<!-- end list -->
261259

@@ -269,4 +267,4 @@ Because JSAction may potentially replay queued events some time after the events
269267
originally fired, certain APIs like `e.preventDefault()` or
270268
`e.stopPropagation()` won't function correctly.
271269

272-
<!-- TODO: Add a comprehensive list of known behavior differences for both replayed and delegated events. There are also plans to emulate some browser behavior (i.e. stopPropagation) that may fix some of these. -->
270+
<!-- TODO: Add a comprehensive list of known behavior differences for both replayed and delegated events. There are also plans to emulate some browser behavior (i.e. stopPropagation) that may fix some of these. -->

packages/core/primitives/event-dispatch/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
export {BaseDispatcher, registerDispatcher} from './src/base_dispatcher';
9+
export {Dispatcher, registerDispatcher} from './src/dispatcher';
1010
export {EventContractContainer} from './src/event_contract_container';
1111
export type {EarlyJsactionDataContainer} from './src/earlyeventcontract';
1212
export {EventContract} from './src/eventcontract';

packages/core/primitives/event-dispatch/src/base_dispatcher.ts

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)