From 70ed87515868d3cfdbb91805d27b1b5924e0a25d Mon Sep 17 00:00:00 2001 From: Johan Bay Date: Wed, 7 Oct 2020 10:15:54 +0200 Subject: [PATCH] fix(queryhandler) only expose custom handlers (#6475) This commit changes the custom query handler API to only operate on user-defined query handlers. --- src/common/QueryHandler.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/common/QueryHandler.ts b/src/common/QueryHandler.ts index 9f4144e9..1706ea77 100644 --- a/src/common/QueryHandler.ts +++ b/src/common/QueryHandler.ts @@ -101,11 +101,8 @@ const _defaultHandler = makeQueryHandler({ element.querySelectorAll(selector), }); -const _builtInHandlers: Array<[string, InternalQueryHandler]> = [ - ['aria', ariaHandler], -]; - -const _queryHandlers = new Map(_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(