fix(queryhandler) only expose custom handlers (#6475)

This commit changes the custom query handler API to only operate on user-defined query handlers.
This commit is contained in:
Johan Bay 2020-10-07 10:15:54 +02:00 committed by GitHub
parent 950ae334ca
commit 70ed875158
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -101,11 +101,8 @@ const _defaultHandler = makeQueryHandler({
element.querySelectorAll(selector),
});
const _builtInHandlers: Array<[string, InternalQueryHandler]> = [
['aria', ariaHandler],
];
const _queryHandlers = new Map<string, InternalQueryHandler>(_builtInHandlers);
const _builtInHandlers = new Map([['aria', ariaHandler]]);
const _queryHandlers = new Map(_builtInHandlers);
export function registerCustomQueryHandler(
name: string,
@ -127,17 +124,19 @@ export function registerCustomQueryHandler(
* @param {string} name
*/
export function unregisterCustomQueryHandler(name: string): void {
if (_queryHandlers.has(name)) {
if (_queryHandlers.has(name) && !_builtInHandlers.has(name)) {
_queryHandlers.delete(name);
}
}
export function customQueryHandlerNames(): string[] {
return [..._queryHandlers.keys()];
return [..._queryHandlers.keys()].filter(
(name) => !_builtInHandlers.has(name)
);
}
export function clearCustomQueryHandlers(): void {
_queryHandlers.clear();
customQueryHandlerNames().forEach(unregisterCustomQueryHandler);
}
export function getQueryHandlerAndSelector(