Skip to content

Commit 3068de4

Browse files
iterianiatscott
authored andcommitted
refactor(core): Remove enums from event-dispatch. (angular#55421)
These cause optimization issues in external. PR Close angular#55421
1 parent 85ac2de commit 3068de4

File tree

8 files changed

+125
-123
lines changed

8 files changed

+125
-123
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import {Attribute} from './attribute';
1010
import {Char} from './char';
1111
import {EventType} from './event_type';
12-
import {Property} from './property';
12+
import {OWNER} from './property';
1313
import * as a11yClick from './a11y_click';
1414
import * as cache from './cache';
1515
import * as eventInfoLib from './event_info';
@@ -143,8 +143,8 @@ export class ActionResolver {
143143
// ancestor chain of the event target node.
144144
break;
145145
}
146-
if (actionElement[Property.OWNER]) {
147-
actionElement = actionElement[Property.OWNER] as Element;
146+
if (actionElement[OWNER]) {
147+
actionElement = actionElement[OWNER] as Element;
148148
continue;
149149
}
150150
if (actionElement.parentNode?.nodeName !== '#document-fragment') {

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

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,72 +6,72 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
export enum Attribute {
10-
/**
11-
* The jsaction attribute defines a mapping of a DOM event to a
12-
* generic event (aka jsaction), to which the actual event handlers
13-
* that implement the behavior of the application are bound. The
14-
* value is a semicolon separated list of colon separated pairs of
15-
* an optional DOM event name and a jsaction name. If the optional
16-
* DOM event name is omitted, 'click' is assumed. The jsaction names
17-
* are dot separated pairs of a namespace and a simple jsaction
18-
* name. If the namespace is absent, it is taken from the closest
19-
* ancestor element with a jsnamespace attribute, if there is
20-
* any. If there is no ancestor with a jsnamespace attribute, the
21-
* simple name is assumed to be the jsaction name.
22-
*
23-
* Used by EventContract.
24-
*/
25-
JSACTION = 'jsaction',
9+
/**
10+
* The jsaction attribute defines a mapping of a DOM event to a
11+
* generic event (aka jsaction), to which the actual event handlers
12+
* that implement the behavior of the application are bound. The
13+
* value is a semicolon separated list of colon separated pairs of
14+
* an optional DOM event name and a jsaction name. If the optional
15+
* DOM event name is omitted, 'click' is assumed. The jsaction names
16+
* are dot separated pairs of a namespace and a simple jsaction
17+
* name. If the namespace is absent, it is taken from the closest
18+
* ancestor element with a jsnamespace attribute, if there is
19+
* any. If there is no ancestor with a jsnamespace attribute, the
20+
* simple name is assumed to be the jsaction name.
21+
*
22+
* Used by EventContract.
23+
*/
24+
export const JSACTION = 'jsaction';
2625

27-
/**
28-
* The jsnamespace attribute provides the namespace part of the
29-
* jaction names occurring in the jsaction attribute where it's
30-
* missing.
31-
*
32-
* Used by EventContract.
33-
*/
34-
JSNAMESPACE = 'jsnamespace',
26+
/**
27+
* The jsnamespace attribute provides the namespace part of the
28+
* jaction names occurring in the jsaction attribute where it's
29+
* missing.
30+
*
31+
* Used by EventContract.
32+
*/
33+
export const JSNAMESPACE = 'jsnamespace';
3534

36-
/**
37-
* The oi attribute is a log impression tag for impression logging
38-
* and action tracking. For an element that carries a jsaction
39-
* attribute, the element is identified for the purpose of
40-
* impression logging and click tracking by the dot separated path
41-
* of all oi attributes in the chain of ancestors of the element.
42-
*
43-
* Used by ActionFlow.
44-
*/
45-
OI = 'oi',
35+
/**
36+
* The oi attribute is a log impression tag for impression logging
37+
* and action tracking. For an element that carries a jsaction
38+
* attribute, the element is identified for the purpose of
39+
* impression logging and click tracking by the dot separated path
40+
* of all oi attributes in the chain of ancestors of the element.
41+
*
42+
* Used by ActionFlow.
43+
*/
44+
export const OI = 'oi';
4645

47-
/**
48-
* The ved attribute is an encoded ClickTrackingCGI proto to track
49-
* visual elements.
50-
*
51-
* Used by ActionFlow.
52-
*/
53-
VED = 'ved',
46+
/**
47+
* The ved attribute is an encoded ClickTrackingCGI proto to track
48+
* visual elements.
49+
*
50+
* Used by ActionFlow.
51+
*/
52+
export const VED = 'ved';
5453

55-
/**
56-
* The vet attribute is the visual element type used to identify tracked
57-
* visual elements.
58-
*/
59-
VET = 'vet',
54+
/**
55+
* The vet attribute is the visual element type used to identify tracked
56+
* visual elements.
57+
*/
58+
export const VET = 'vet';
59+
60+
/**
61+
* Support for iteration on reprocessing.
62+
*
63+
* Used by ActionFlow.
64+
*/
65+
export const JSINSTANCE = 'jsinstance';
6066

61-
/**
62-
* Support for iteration on reprocessing.
63-
*
64-
* Used by ActionFlow.
65-
*/
66-
JSINSTANCE = 'jsinstance',
67+
/**
68+
* All click jsactions that happen on the element that carries this
69+
* attribute or its descendants are automatically logged.
70+
* Impressions of jsactions on these elements are tracked too, if
71+
* requested by the impression() method of ActionFlow.
72+
*
73+
* Used by ActionFlow.
74+
*/
75+
export const JSTRACK = 'jstrack';
6776

68-
/**
69-
* All click jsactions that happen on the element that carries this
70-
* attribute or its descendants are automatically logged.
71-
* Impressions of jsactions on these elements are tracked too, if
72-
* requested by the impression() method of ActionFlow.
73-
*
74-
* Used by ActionFlow.
75-
*/
76-
JSTRACK = 'jstrack',
77-
}
77+
export const Attribute = {JSACTION, JSNAMESPACE, OI, VED, VET, JSINSTANCE, JSTRACK};

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

Lines changed: 9 additions & 9 deletions
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-
import {Property} from './property';
9+
import {JSACTION, JSNAMESPACE} from './property';
1010

1111
/**
1212
* Map from jsaction annotation to a parsed map from event name to action name.
@@ -21,7 +21,7 @@ const parseCache: {[key: string]: {[key: string]: string}} = {};
2121
*/
2222
export function get(element: Element): {[key: string]: string} {
2323
// @ts-ignore
24-
return element[Property.JSACTION];
24+
return element[JSACTION];
2525
}
2626

2727
/**
@@ -33,7 +33,7 @@ export function get(element: Element): {[key: string]: string} {
3333
*/
3434
export function set(element: Element, actionMap: {[key: string]: string}) {
3535
// @ts-ignore
36-
element[Property.JSACTION] = actionMap;
36+
element[JSACTION] = actionMap;
3737
}
3838

3939
/**
@@ -62,8 +62,8 @@ export function setParsed(text: string, parsed: {[key: string]: string}) {
6262
* @param element .
6363
*/
6464
export function clear(element: Element) {
65-
if (Property.JSACTION in element) {
66-
delete element[Property.JSACTION];
65+
if (JSACTION in element) {
66+
delete element[JSACTION];
6767
}
6868
}
6969

@@ -77,7 +77,7 @@ export function clear(element: Element) {
7777
*/
7878
export function getNamespace(element: Element): string | null | undefined {
7979
// @ts-ignore
80-
return element[Property.JSNAMESPACE];
80+
return element[JSNAMESPACE];
8181
}
8282

8383
/**
@@ -89,7 +89,7 @@ export function getNamespace(element: Element): string | null | undefined {
8989
*/
9090
export function setNamespace(element: Element, jsnamespace: string | null) {
9191
// @ts-ignore
92-
element[Property.JSNAMESPACE] = jsnamespace;
92+
element[JSNAMESPACE] = jsnamespace;
9393
}
9494

9595
/**
@@ -98,7 +98,7 @@ export function setNamespace(element: Element, jsnamespace: string | null) {
9898
* @param element .
9999
*/
100100
export function clearNamespace(element: Element) {
101-
if (Property.JSNAMESPACE in element) {
102-
delete element[Property.JSNAMESPACE];
101+
if (JSNAMESPACE in element) {
102+
delete element[JSNAMESPACE];
103103
}
104104
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
/** Special keycodes used by jsaction for the generic click action. */
10-
export enum KeyCode {
11-
/**
12-
* If on a Macintosh with an extended keyboard, the Enter key located in the
13-
* numeric pad has a different ASCII code.
14-
*/
15-
MAC_ENTER = 3,
9+
/**
10+
* If on a Macintosh with an extended keyboard, the Enter key located in the
11+
* numeric pad has a different ASCII code.
12+
*/
13+
export const MAC_ENTER = 3;
1614

17-
/** The Enter key. */
18-
ENTER = 13,
15+
/** The Enter key. */
16+
export const ENTER = 13;
1917

20-
/** The Space key. */
21-
SPACE = 32,
22-
}
18+
/** The Space key. */
19+
export const SPACE = 32;
20+
21+
/** Special keycodes used by jsaction for the generic click action. */
22+
export const KeyCode = {MAC_ENTER, ENTER, SPACE};

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

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,46 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
/** All properties that are used by jsaction. */
10-
export enum Property {
11-
/**
12-
* The parsed value of the jsaction attribute is stored in this
13-
* property on the DOM node. The parsed value is an Object. The
14-
* property names of the object are the events; the values are the
15-
* names of the actions. This property is attached even on nodes
16-
* that don't have a jsaction attribute as an optimization, because
17-
* property lookup is faster than attribute access.
18-
*/
19-
JSACTION = '__jsaction',
9+
/**
10+
* The parsed value of the jsaction attribute is stored in this
11+
* property on the DOM node. The parsed value is an Object. The
12+
* property names of the object are the events; the values are the
13+
* names of the actions. This property is attached even on nodes
14+
* that don't have a jsaction attribute as an optimization, because
15+
* property lookup is faster than attribute access.
16+
*/
17+
export const JSACTION = '__jsaction';
18+
19+
/**
20+
* The parsed value of the jsnamespace attribute is stored in this
21+
* property on the DOM node.
22+
*/
23+
export const JSNAMESPACE = '__jsnamespace';
2024

21-
/**
22-
* The parsed value of the jsnamespace attribute is stored in this
23-
* property on the DOM node.
24-
*/
25-
JSNAMESPACE = '__jsnamespace',
25+
/** The value of the oi attribute as a property, for faster access. */
26+
export const OI = '__oi';
2627

27-
/** The value of the oi attribute as a property, for faster access. */
28-
OI = '__oi',
28+
/**
29+
* The owner property references an a logical owner for a DOM node. JSAction
30+
* will follow this reference instead of parentNode when traversing the DOM
31+
* to find jsaction attributes. This allows overlaying a logical structure
32+
* over a document where the DOM structure can't reflect that structure.
33+
*/
34+
export const OWNER = '__owner';
2935

30-
/**
31-
* The owner property references an a logical owner for a DOM node. JSAction
32-
* will follow this reference instead of parentNode when traversing the DOM
33-
* to find jsaction attributes. This allows overlaying a logical structure
34-
* over a document where the DOM structure can't reflect that structure.
35-
*/
36-
OWNER = '__owner',
37-
}
36+
/** All properties that are used by jsaction. */
37+
export const Property = {
38+
JSACTION,
39+
JSNAMESPACE,
40+
OI,
41+
OWNER,
42+
};
3843

3944
declare global {
4045
interface Node {
41-
[Property.JSACTION]?: string;
42-
[Property.JSNAMESPACE]?: string;
43-
[Property.OI]?: string;
44-
[Property.OWNER]?: ParentNode;
46+
[JSACTION]?: string;
47+
[JSNAMESPACE]?: string;
48+
[OI]?: string;
49+
[OWNER]?: ParentNode;
4550
}
4651
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
*/
1212

1313
export enum Restriction {
14-
I_AM_THE_JSACTION_FRAMEWORK = 1,
14+
I_AM_THE_JSACTION_FRAMEWORK,
1515
}

packages/core/primitives/event-dispatch/test/eventcontract_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {EventContractMultiContainer} from '../src/event_contract_multi_container
2222
import {EventInfo, EventInfoWrapper} from '../src/event_info';
2323
import {EventType} from '../src/event_type';
2424
import {addDeferredA11yClickSupport, Dispatcher, EventContract} from '../src/eventcontract';
25-
import {Property} from '../src/property';
25+
import {OWNER} from '../src/property';
2626
import {Restriction} from '../src/restriction';
2727

2828
import {safeElement, testonlyHtml} from './html';
@@ -515,7 +515,7 @@ describe('EventContract', () => {
515515
const container = getRequiredElementById('owner-click-container');
516516
const actionElement = getRequiredElementById('owner-click-action-element');
517517
const targetElement = getRequiredElementById('owner-click-target-element');
518-
targetElement[Property.OWNER] = actionElement;
518+
targetElement[OWNER] = actionElement;
519519

520520
const dispatcher = jasmine.createSpy<Dispatcher>('dispatcher');
521521
createEventContract({

packages/core/test/bundling/defer/bundle.golden_symbols.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,6 @@
233233
{
234234
"name": "InputFlags"
235235
},
236-
{
237-
"name": "KeyCode"
238-
},
239236
{
240237
"name": "KeyEventsPlugin"
241238
},

0 commit comments

Comments
 (0)