Skip to content

Commit

Permalink
fix(queryhandler) only expose custom handlers (#6475)
Browse files Browse the repository at this point in the history
This commit changes the custom query handler API to only operate on user-defined query handlers.
  • Loading branch information
johanbay committed Oct 7, 2020
1 parent 950ae33 commit 70ed875
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/common/QueryHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit 70ed875

Please sign in to comment.