Skip to content

Commit 8483721

Browse files
rahatarmanahmedAndrewKushnir
authored andcommitted
refactor(core): Remove unused JSNAMESPACE_SUPPORT from event-dispatch (angular#55619)
The usage of this option has been removed from google3 code, so we don't need to keep it around anymore. PR Close angular#55619
1 parent 0510930 commit 8483721

File tree

5 files changed

+3
-202
lines changed

5 files changed

+3
-202
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ export class EventContract implements UnrenamedEventContract {
4444
exportAddA11yClickSupport(): void;
4545
handler(eventType: string): EventHandler | undefined;
4646
// (undocumented)
47-
static JSNAMESPACE_SUPPORT: boolean;
48-
// (undocumented)
4947
static MOUSE_SPECIAL_SUPPORT: boolean;
5048
registerDispatcher(dispatcher: Dispatcher_2, restriction: Restriction): void;
5149
replayEarlyEvents(earlyJsactionContainer?: EarlyJsactionDataContainer): void;

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

Lines changed: 3 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const DEFAULT_EVENT_TYPE: string = EventType.CLICK;
3333
export class ActionResolver {
3434
private a11yClickSupport: boolean = false;
3535
private readonly customEventSupport: boolean;
36-
private readonly jsnamespaceSupport: boolean;
3736
private readonly syntheticMouseEventSupport: boolean;
3837

3938
private updateEventInfoForA11yClick?: (eventInfo: eventInfoLib.EventInfo) => void = undefined;
@@ -48,15 +47,12 @@ export class ActionResolver {
4847

4948
constructor({
5049
customEventSupport = false,
51-
jsnamespaceSupport = false,
5250
syntheticMouseEventSupport = false,
5351
}: {
5452
customEventSupport?: boolean;
55-
jsnamespaceSupport?: boolean;
5653
syntheticMouseEventSupport?: boolean;
5754
} = {}) {
5855
this.customEventSupport = customEventSupport;
59-
this.jsnamespaceSupport = jsnamespaceSupport;
6056
this.syntheticMouseEventSupport = syntheticMouseEventSupport;
6157
}
6258

@@ -214,17 +210,14 @@ export class ActionResolver {
214210
* action the given event is mapped to, if any. It parses the
215211
* attribute value and stores it in a property on the node for
216212
* subsequent retrieval without re-parsing and re-accessing the
217-
* attribute. In order to fully qualify jsaction names using a
218-
* namespace, the DOM is searched starting at the current node and
219-
* going through ancestor nodes until a jsnamespace attribute is
220-
* found.
213+
* attribute.
221214
*
222215
* @param actionElement The DOM node to retrieve the jsaction map from.
223216
* @param eventInfo `EventInfo` to set `action` and `actionElement` if an
224217
* action is found on the `actionElement`.
225218
*/
226219
private populateActionOnElement(actionElement: Element, eventInfo: eventInfoLib.EventInfo) {
227-
const actionMap = this.parseActions(actionElement, eventInfoLib.getContainer(eventInfo));
220+
const actionMap = this.parseActions(actionElement);
228221

229222
const actionName = actionMap[eventInfoLib.getEventType(eventInfo)];
230223
if (actionName !== undefined) {
@@ -242,11 +235,9 @@ export class ActionResolver {
242235
* This is primarily for internal use.
243236
*
244237
* @param actionElement The DOM node to retrieve the jsaction map from.
245-
* @param container The node which limits the namespace lookup for a jsaction
246-
* name. The container node itself will not be searched.
247238
* @return Map from event to qualified name of the jsaction bound to it.
248239
*/
249-
private parseActions(actionElement: Element, container: Node): {[key: string]: string} {
240+
private parseActions(actionElement: Element): {[key: string]: string} {
250241
let actionMap: {[key: string]: string} | undefined = cache.get(actionElement);
251242
if (!actionMap) {
252243
const jsactionAttribute = actionElement.getAttribute(Attribute.JSACTION);
@@ -271,58 +262,12 @@ export class ActionResolver {
271262
}
272263
cache.setParsed(jsactionAttribute, actionMap);
273264
}
274-
// If namespace support is active we need to augment the (potentially
275-
// cached) jsaction mapping with the namespace.
276-
if (this.jsnamespaceSupport) {
277-
const noNs = actionMap;
278-
actionMap = {};
279-
for (const type in noNs) {
280-
actionMap[type] = this.getFullyQualifiedAction(noNs[type], actionElement, container);
281-
}
282-
}
283265
cache.set(actionElement, actionMap);
284266
}
285267
}
286268
return actionMap;
287269
}
288270

289-
/**
290-
* Returns the fully qualified jsaction action. If the given jsaction
291-
* name doesn't already contain the namespace, the function iterates
292-
* over ancestor nodes until a jsnamespace attribute is found, and
293-
* uses the value of that attribute as the namespace.
294-
*
295-
* @param action The jsaction action to resolve.
296-
* @param start The node from which to start searching for a jsnamespace
297-
* attribute.
298-
* @param container The node which limits the search for a jsnamespace
299-
* attribute. This node will be searched.
300-
* @return The fully qualified name of the jsaction. If no namespace is found,
301-
* returns the unqualified name in case it exists in the global namespace.
302-
*/
303-
private getFullyQualifiedAction(action: string, start: Element, container: Node): string {
304-
if (isNamespacedAction(action)) {
305-
return action;
306-
}
307-
308-
let node: Node | null = start;
309-
while (node && node.nodeType === Node.ELEMENT_NODE) {
310-
const namespace = getNamespaceFromElement(node as Element);
311-
if (namespace) {
312-
return namespace + Char.NAMESPACE_ACTION_SEPARATOR + action;
313-
}
314-
315-
// If this node is the container, stop.
316-
if (node === container) {
317-
break;
318-
}
319-
320-
node = node.parentNode;
321-
}
322-
323-
return action;
324-
}
325-
326271
addA11yClickSupport(
327272
updateEventInfoForA11yClick: typeof a11yClick.updateEventInfoForA11yClick,
328273
preventDefaultForA11yClick: typeof a11yClick.preventDefaultForA11yClick,
@@ -334,29 +279,3 @@ export class ActionResolver {
334279
this.populateClickOnlyAction = populateClickOnlyAction;
335280
}
336281
}
337-
338-
/**
339-
* Checks if a jsaction action contains a namespace part.
340-
*/
341-
function isNamespacedAction(action: string): boolean {
342-
return action.indexOf(Char.NAMESPACE_ACTION_SEPARATOR) >= 0;
343-
}
344-
345-
/**
346-
* Returns the value of the jsnamespace attribute of the given node.
347-
* Also caches the value for subsequent lookups.
348-
* @param element The node whose jsnamespace attribute is being asked for.
349-
* @return The value of the jsnamespace attribute, or null if not found.
350-
*/
351-
function getNamespaceFromElement(element: Element): string | null {
352-
let namespace = cache.getNamespace(element);
353-
// Only query for the attribute if it has not been queried for
354-
// before. getAttribute() returns null if an attribute is not present. Thus,
355-
// namespace is string|null if the query took place in the past, or
356-
// undefined if the query did not take place.
357-
if (namespace === undefined) {
358-
namespace = element.getAttribute(Attribute.JSNAMESPACE);
359-
cache.setNamespace(element, namespace);
360-
}
361-
return namespace;
362-
}

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

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

9-
/**
10-
* @define Support for jsnamespace attribute. This flag can be overridden in a
11-
* build rule to trim down the EventContract's binary size.
12-
*/
13-
export const JSNAMESPACE_SUPPORT = false;
14-
159
/**
1610
* @define Support for accessible click actions. This flag can be overridden in
1711
* a build rule.

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import {EventContractContainerManager} from './event_contract_container';
3838
import {
3939
A11Y_CLICK_SUPPORT,
4040
CUSTOM_EVENT_SUPPORT,
41-
JSNAMESPACE_SUPPORT,
4241
MOUSE_SPECIAL_SUPPORT,
4342
} from './event_contract_defines';
4443
import * as eventInfoLib from './event_info';
@@ -91,13 +90,11 @@ export class EventContract implements UnrenamedEventContract {
9190
static CUSTOM_EVENT_SUPPORT = CUSTOM_EVENT_SUPPORT;
9291
static A11Y_CLICK_SUPPORT = A11Y_CLICK_SUPPORT;
9392
static MOUSE_SPECIAL_SUPPORT = MOUSE_SPECIAL_SUPPORT;
94-
static JSNAMESPACE_SUPPORT = JSNAMESPACE_SUPPORT;
9593

9694
private containerManager: EventContractContainerManager | null;
9795

9896
private readonly actionResolver = new ActionResolver({
9997
customEventSupport: EventContract.CUSTOM_EVENT_SUPPORT,
100-
jsnamespaceSupport: EventContract.JSNAMESPACE_SUPPORT,
10198
syntheticMouseEventSupport: EventContract.MOUSE_SPECIAL_SUPPORT,
10299
});
103100

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

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,113 +1781,6 @@ describe('EventContract', () => {
17811781
});
17821782
});
17831783

1784-
describe('jsnamespace', () => {
1785-
beforeEach(() => {
1786-
EventContract.JSNAMESPACE_SUPPORT = true;
1787-
});
1788-
1789-
it('dispatches event', () => {
1790-
const container = getRequiredElementById('jsnamespace-container');
1791-
const actionElement = getRequiredElementById('jsnamespace-action-element');
1792-
const targetElement = getRequiredElementById('jsnamespace-target-element');
1793-
1794-
const dispatcher = jasmine.createSpy<Dispatcher>('dispatcher');
1795-
createEventContract({
1796-
eventContractContainerManager: new EventContractContainer(container),
1797-
eventTypes: ['click'],
1798-
dispatcher,
1799-
});
1800-
1801-
const clickEvent = dispatchMouseEvent(targetElement);
1802-
1803-
expect(dispatcher).toHaveBeenCalledTimes(2);
1804-
const eventInfoWrapper = getLastDispatchedEventInfoWrapper(dispatcher);
1805-
expect(eventInfoWrapper.getEventType()).toBe('click');
1806-
expect(eventInfoWrapper.getEvent()).toBe(clickEvent);
1807-
expect(eventInfoWrapper.getTargetElement()).toBe(targetElement);
1808-
expect(eventInfoWrapper.getAction()?.name).toBe('namespace.handleClick');
1809-
expect(eventInfoWrapper.getAction()?.element).toBe(actionElement);
1810-
});
1811-
1812-
it('caches namespace attribute', () => {
1813-
const container = getRequiredElementById('jsnamespace-container');
1814-
const namespaceElement = getRequiredElementById('jsnamespace-namespace-element');
1815-
const actionElement = getRequiredElementById('jsnamespace-action-element');
1816-
const targetElement = getRequiredElementById('jsnamespace-target-element');
1817-
1818-
const dispatcher = jasmine.createSpy<Dispatcher>('dispatcher');
1819-
createEventContract({
1820-
eventContractContainerManager: new EventContractContainer(container),
1821-
eventTypes: ['click'],
1822-
dispatcher,
1823-
});
1824-
1825-
let clickEvent = dispatchMouseEvent(targetElement);
1826-
1827-
expect(dispatcher).toHaveBeenCalledTimes(2);
1828-
let eventInfoWrapper = getLastDispatchedEventInfoWrapper(dispatcher);
1829-
expect(eventInfoWrapper.getEventType()).toBe('click');
1830-
expect(eventInfoWrapper.getEvent()).toBe(clickEvent);
1831-
expect(eventInfoWrapper.getTargetElement()).toBe(targetElement);
1832-
expect(eventInfoWrapper.getAction()?.name).toBe('namespace.handleClick');
1833-
expect(eventInfoWrapper.getAction()?.element).toBe(actionElement);
1834-
1835-
namespaceElement.setAttribute('jsnamespace', 'renamedNamespace');
1836-
dispatcher.calls.reset();
1837-
1838-
clickEvent = dispatchMouseEvent(targetElement);
1839-
1840-
expect(dispatcher).toHaveBeenCalledTimes(2);
1841-
eventInfoWrapper = getLastDispatchedEventInfoWrapper(dispatcher);
1842-
expect(eventInfoWrapper.getEventType()).toBe('click');
1843-
expect(eventInfoWrapper.getEvent()).toBe(clickEvent);
1844-
expect(eventInfoWrapper.getTargetElement()).toBe(targetElement);
1845-
expect(eventInfoWrapper.getAction()?.name).toBe('namespace.handleClick');
1846-
expect(eventInfoWrapper.getAction()?.element).toBe(actionElement);
1847-
});
1848-
1849-
it('re-parses jsaction attribute if the action cache is cleared', () => {
1850-
const container = getRequiredElementById('jsnamespace-container');
1851-
const namespaceElement = getRequiredElementById('jsnamespace-namespace-element');
1852-
const actionElement = getRequiredElementById('jsnamespace-action-element');
1853-
const targetElement = getRequiredElementById('jsnamespace-target-element');
1854-
1855-
const dispatcher = jasmine.createSpy<Dispatcher>('dispatcher');
1856-
createEventContract({
1857-
eventContractContainerManager: new EventContractContainer(container),
1858-
eventTypes: ['click'],
1859-
dispatcher,
1860-
});
1861-
1862-
let clickEvent = dispatchMouseEvent(targetElement);
1863-
1864-
expect(dispatcher).toHaveBeenCalledTimes(2);
1865-
let eventInfoWrapper = getLastDispatchedEventInfoWrapper(dispatcher);
1866-
expect(eventInfoWrapper.getEventType()).toBe('click');
1867-
expect(eventInfoWrapper.getEvent()).toBe(clickEvent);
1868-
expect(eventInfoWrapper.getTargetElement()).toBe(targetElement);
1869-
expect(eventInfoWrapper.getAction()?.name).toBe('namespace.handleClick');
1870-
expect(eventInfoWrapper.getAction()?.element).toBe(actionElement);
1871-
1872-
namespaceElement.setAttribute('jsnamespace', 'renamedNamespace');
1873-
// Clear namespace cache.
1874-
cache.clearNamespace(namespaceElement);
1875-
// Clear action cache.
1876-
cache.clear(actionElement);
1877-
dispatcher.calls.reset();
1878-
1879-
clickEvent = dispatchMouseEvent(targetElement);
1880-
1881-
expect(dispatcher).toHaveBeenCalledTimes(2);
1882-
eventInfoWrapper = getLastDispatchedEventInfoWrapper(dispatcher);
1883-
expect(eventInfoWrapper.getEventType()).toBe('click');
1884-
expect(eventInfoWrapper.getEvent()).toBe(clickEvent);
1885-
expect(eventInfoWrapper.getTargetElement()).toBe(targetElement);
1886-
expect(eventInfoWrapper.getAction()?.name).toBe('renamedNamespace.handleClick');
1887-
expect(eventInfoWrapper.getAction()?.element).toBe(actionElement);
1888-
});
1889-
});
1890-
18911784
describe('early events', () => {
18921785
let removeEventListenerSpy: jasmine.Spy;
18931786

0 commit comments

Comments
 (0)