From 291f38115c40c209c88ce509d5163375b34d04a9 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 8 Feb 2023 17:48:26 -0300 Subject: [PATCH] New webpack filter: byDisplayName (#474) --- src/webpack/webpack.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index 0bbd8150..e537740f 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -50,6 +50,8 @@ export const filters = { } return true; }, + byDisplayName: (name: string): FilterFn => m => + m.constructor?.displayName === name }; export const subscriptions = new Map(); @@ -326,6 +328,20 @@ export function findByCodeLazy(...code: string[]) { return findLazy(filters.byCode(...code)); } +/** + * Find a store by its displayName + */ +export function findByDisplayName(name: string) { + return find(filters.byDisplayName(name)); +} + +/** + * findByDisplayName but lazy + */ +export function findByDisplayNameLazy(name: string) { + return findLazy(filters.byDisplayName(name)); +} + /** * Wait for a module that matches the provided filter to be registered, * then call the callback with the module as the first argument