Skip to content

Commit 28e48ed

Browse files
committed
refactor: add function to create context provider registry
1 parent 220fafb commit 28e48ed

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/context/registry.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@ import _ from "underscore";
33

44
import * as allContextProviders from "./providers";
55

6-
_.map(allContextProviders, (instance, name) =>
7-
clsInstance.addProvider({
8-
instance,
9-
name,
10-
}),
11-
);
6+
/** Create registry of context providers
7+
*
8+
* @summary: Adds context providers to registry and patches them with a static
9+
* class variable if classes are provided with `classesToPatch`.
10+
*/
11+
export const createRegistry = (classesToPatch = []) => {
12+
return _.map(allContextProviders, (instance, name) => {
13+
classesToPatch.forEach((cls) => (instance[cls.name] = cls));
14+
return clsInstance.addProvider({
15+
instance,
16+
name,
17+
});
18+
});
19+
};
1220

13-
export const ContextProviderRegistry = clsInstance;
21+
export const ContextProviderRegistry = createRegistry();

0 commit comments

Comments
 (0)