Skip to content

Commit

Permalink
feat(core): Remove enums from event-dispatch.
Browse files Browse the repository at this point in the history
These cause optimization issues in external.
  • Loading branch information
iteriani committed Apr 22, 2024
1 parent bac5ba3 commit 127d9f2
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 173 deletions.
56 changes: 29 additions & 27 deletions packages/core/primitives/event-dispatch/src/accessibility.ts
Expand Up @@ -6,39 +6,41 @@
* found in the LICENSE file at https://angular.io/license
*/

/**
* An event-type set when the event contract detects a KEYDOWN event but
* doesn't know if the key press can be treated like a click. The dispatcher
* will use this event-type to parse the keypress and handle it accordingly.
*/
export const MAYBE_CLICK_EVENT_TYPE = 'maybe_click';
/**
* A property added to a dispatched event that had the MAYBE_CLICK_EVENTTYPE
* event-type but could not be used as a click. The dispatcher sets this
* property for non-global dispatches before it retriggers the event and it
* signifies that the event contract should not dispatch this event globally.
*/
export const SKIP_GLOBAL_DISPATCH = 'a11ysgd';
/**
* A property added to a dispatched event that had the MAYBE_CLICK_EVENTTYPE
* event-type but could not be used as a click. The dispatcher sets this
* property before it retriggers the event and it signifies that the event
* contract should not look at CLICK actions for KEYDOWN events.
*/
export const SKIP_A11Y_CHECK = 'a11ysc';

/**
* Defines special EventInfo and Event properties used when
* A11Y_SUPPORT_IN_DISPATCHER is enabled.
*/
export enum Attribute {
/**
* An event-type set when the event contract detects a KEYDOWN event but
* doesn't know if the key press can be treated like a click. The dispatcher
* will use this event-type to parse the keypress and handle it accordingly.
*/
MAYBE_CLICK_EVENT_TYPE = 'maybe_click',

/**
* A property added to a dispatched event that had the MAYBE_CLICK_EVENTTYPE
* event-type but could not be used as a click. The dispatcher sets this
* property for non-global dispatches before it retriggers the event and it
* signifies that the event contract should not dispatch this event globally.
*/
SKIP_GLOBAL_DISPATCH = 'a11ysgd',

/**
* A property added to a dispatched event that had the MAYBE_CLICK_EVENTTYPE
* event-type but could not be used as a click. The dispatcher sets this
* property before it retriggers the event and it signifies that the event
* contract should not look at CLICK actions for KEYDOWN events.
*/
SKIP_A11Y_CHECK = 'a11ysc',
}
export const Attribute = {
MAYBE_CLICK_EVENT_TYPE,
SKIP_GLOBAL_DISPATCH,
SKIP_A11Y_CHECK,
};

declare global {
interface Event {
[Attribute.MAYBE_CLICK_EVENT_TYPE]?: boolean;
[Attribute.SKIP_GLOBAL_DISPATCH]?: boolean;
[Attribute.SKIP_A11Y_CHECK]?: boolean;
[MAYBE_CLICK_EVENT_TYPE]?: boolean;
[SKIP_GLOBAL_DISPATCH]?: boolean;
[SKIP_A11Y_CHECK]?: boolean;
}
}
126 changes: 63 additions & 63 deletions packages/core/primitives/event-dispatch/src/attribute.ts
Expand Up @@ -6,72 +6,72 @@
* found in the LICENSE file at https://angular.io/license
*/

export enum Attribute {
/**
* The jsaction attribute defines a mapping of a DOM event to a
* generic event (aka jsaction), to which the actual event handlers
* that implement the behavior of the application are bound. The
* value is a semicolon separated list of colon separated pairs of
* an optional DOM event name and a jsaction name. If the optional
* DOM event name is omitted, 'click' is assumed. The jsaction names
* are dot separated pairs of a namespace and a simple jsaction
* name. If the namespace is absent, it is taken from the closest
* ancestor element with a jsnamespace attribute, if there is
* any. If there is no ancestor with a jsnamespace attribute, the
* simple name is assumed to be the jsaction name.
*
* Used by EventContract.
*/
JSACTION = 'jsaction',
/**
* The jsaction attribute defines a mapping of a DOM event to a
* generic event (aka jsaction), to which the actual event handlers
* that implement the behavior of the application are bound. The
* value is a semicolon separated list of colon separated pairs of
* an optional DOM event name and a jsaction name. If the optional
* DOM event name is omitted, 'click' is assumed. The jsaction names
* are dot separated pairs of a namespace and a simple jsaction
* name. If the namespace is absent, it is taken from the closest
* ancestor element with a jsnamespace attribute, if there is
* any. If there is no ancestor with a jsnamespace attribute, the
* simple name is assumed to be the jsaction name.
*
* Used by EventContract.
*/
export const JSACTION = 'jsaction';

/**
* The jsnamespace attribute provides the namespace part of the
* jaction names occurring in the jsaction attribute where it's
* missing.
*
* Used by EventContract.
*/
JSNAMESPACE = 'jsnamespace',
/**
* The jsnamespace attribute provides the namespace part of the
* jaction names occurring in the jsaction attribute where it's
* missing.
*
* Used by EventContract.
*/
export const JSNAMESPACE = 'jsnamespace';

/**
* The oi attribute is a log impression tag for impression logging
* and action tracking. For an element that carries a jsaction
* attribute, the element is identified for the purpose of
* impression logging and click tracking by the dot separated path
* of all oi attributes in the chain of ancestors of the element.
*
* Used by ActionFlow.
*/
OI = 'oi',
/**
* The oi attribute is a log impression tag for impression logging
* and action tracking. For an element that carries a jsaction
* attribute, the element is identified for the purpose of
* impression logging and click tracking by the dot separated path
* of all oi attributes in the chain of ancestors of the element.
*
* Used by ActionFlow.
*/
export const OI = 'oi';

/**
* The ved attribute is an encoded ClickTrackingCGI proto to track
* visual elements.
*
* Used by ActionFlow.
*/
VED = 'ved',
/**
* The ved attribute is an encoded ClickTrackingCGI proto to track
* visual elements.
*
* Used by ActionFlow.
*/
export const VED = 'ved';

/**
* The vet attribute is the visual element type used to identify tracked
* visual elements.
*/
VET = 'vet',
/**
* The vet attribute is the visual element type used to identify tracked
* visual elements.
*/
export const VET = 'vet';

/**
* Support for iteration on reprocessing.
*
* Used by ActionFlow.
*/
export const JSINSTANCE = 'jsinstance';

/**
* Support for iteration on reprocessing.
*
* Used by ActionFlow.
*/
JSINSTANCE = 'jsinstance',
/**
* All click jsactions that happen on the element that carries this
* attribute or its descendants are automatically logged.
* Impressions of jsactions on these elements are tracked too, if
* requested by the impression() method of ActionFlow.
*
* Used by ActionFlow.
*/
export const JSTRACK = 'jstrack';

/**
* All click jsactions that happen on the element that carries this
* attribute or its descendants are automatically logged.
* Impressions of jsactions on these elements are tracked too, if
* requested by the impression() method of ActionFlow.
*
* Used by ActionFlow.
*/
JSTRACK = 'jstrack',
}
export const Attribute = {JSACTION, JSNAMESPACE, OI, VED, VET, JSINSTANCE, JSTRACK};
18 changes: 9 additions & 9 deletions packages/core/primitives/event-dispatch/src/cache.ts
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Property} from './property';
import {JSACTION, JSNAMESPACE} from './property';

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

/**
Expand All @@ -33,7 +33,7 @@ export function get(element: Element): {[key: string]: string} {
*/
export function set(element: Element, actionMap: {[key: string]: string}) {
// @ts-ignore
element[Property.JSACTION] = actionMap;
element[JSACTION] = actionMap;
}

/**
Expand Down Expand Up @@ -62,8 +62,8 @@ export function setParsed(text: string, parsed: {[key: string]: string}) {
* @param element .
*/
export function clear(element: Element) {
if (Property.JSACTION in element) {
delete element[Property.JSACTION];
if (JSACTION in element) {
delete element[JSACTION];
}
}

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

/**
Expand All @@ -89,7 +89,7 @@ export function getNamespace(element: Element): string | null | undefined {
*/
export function setNamespace(element: Element, jsnamespace: string | null) {
// @ts-ignore
element[Property.JSNAMESPACE] = jsnamespace;
element[JSNAMESPACE] = jsnamespace;
}

/**
Expand All @@ -98,7 +98,7 @@ export function setNamespace(element: Element, jsnamespace: string | null) {
* @param element .
*/
export function clearNamespace(element: Element) {
if (Property.JSNAMESPACE in element) {
delete element[Property.JSNAMESPACE];
if (JSNAMESPACE in element) {
delete element[JSNAMESPACE];
}
}
8 changes: 4 additions & 4 deletions packages/core/primitives/event-dispatch/src/dispatcher.ts
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Attribute as AccessibilityAttribute} from './accessibility';
import {MAYBE_CLICK_EVENT_TYPE, SKIP_A11Y_CHECK, SKIP_GLOBAL_DISPATCH} from './accessibility';
import {Char} from './char';
import * as eventLib from './event';
import {EventInfo, EventInfoWrapper} from './event_info';
Expand Down Expand Up @@ -321,7 +321,7 @@ export class Dispatcher {
* be re-dispatched.
*/
function resolveA11yEvent(eventInfoWrapper: EventInfoWrapper, isGlobalDispatch = false): boolean {
if (eventInfoWrapper.getEventType() !== AccessibilityAttribute.MAYBE_CLICK_EVENT_TYPE) {
if (eventInfoWrapper.getEventType() !== MAYBE_CLICK_EVENT_TYPE) {
return true;
}

Expand All @@ -343,10 +343,10 @@ function resolveA11yEvent(eventInfoWrapper: EventInfoWrapper, isGlobalDispatch =
// This prevents the event contract from setting the
// AccessibilityAttribute.MAYBE_CLICK_EVENT_TYPE type for Keydown
// events.
eventInfoWrapper.getEvent()[AccessibilityAttribute.SKIP_A11Y_CHECK] = true;
eventInfoWrapper.getEvent()[SKIP_A11Y_CHECK] = true;
// Since globally dispatched events will get handled by the dispatcher,
// don't have the event contract dispatch it again.
eventInfoWrapper.getEvent()[AccessibilityAttribute.SKIP_GLOBAL_DISPATCH] = true;
eventInfoWrapper.getEvent()[SKIP_GLOBAL_DISPATCH] = true;
return false;
}
}
Expand Down

0 comments on commit 127d9f2

Please sign in to comment.