@adimm/x-injection-reactjs 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,209 +1,172 @@
1
1
  "use strict";
2
2
 
3
- var e, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, o = Object.prototype.hasOwnProperty, i = (e, n) => t(e, "name", {
4
- value: n,
3
+ var e, t = Object.create, o = Object.defineProperty, r = Object.getOwnPropertyDescriptor, n = Object.getOwnPropertyNames, i = Object.getPrototypeOf, u = Object.prototype.hasOwnProperty, s = (e, t) => o(e, "name", {
4
+ value: t,
5
5
  configurable: !0
6
- }), u = {};
6
+ }), c = (e, t, i, s) => {
7
+ if (t && "object" == typeof t || "function" == typeof t) for (let c of n(t)) u.call(e, c) || c === i || o(e, c, {
8
+ get: () => t[c],
9
+ enumerable: !(s = r(t, c)) || s.enumerable
10
+ });
11
+ return e;
12
+ }, a = {};
7
13
 
8
- ((e, n) => {
9
- for (var r in n) t(e, r, {
10
- get: n[r],
14
+ ((e, t) => {
15
+ for (var r in t) o(e, r, {
16
+ get: t[r],
11
17
  enumerable: !0
12
18
  });
13
- })(u, {
14
- ComponentProviderModule: () => q,
15
- ModuleProvider: () => P,
16
- REACT_X_INJECTION_CONTEXT: () => a,
17
- REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT: () => d,
18
- TapIntoComponent: () => b,
19
- useExposeComponentModuleContext: () => h,
20
- useInject: () => v,
21
- useInjectMany: () => R,
22
- useInjectManyOnRender: () => _,
23
- useInjectOnRender: () => M,
24
- useRerenderOnChildrenModuleContextLoaded: () => y
25
- }), module.exports = (e = u, ((e, i, u, s) => {
26
- if (i && "object" == typeof i || "function" == typeof i) for (let c of r(i)) o.call(e, c) || c === u || t(e, c, {
27
- get: () => i[c],
28
- enumerable: !(s = n(i, c)) || s.enumerable
29
- });
30
- return e;
31
- })(t({}, "__esModule", {
19
+ })(a, {
20
+ ComponentProviderModule: () => C,
21
+ ProvideModule: () => I,
22
+ REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT: () => p,
23
+ hookFactory: () => q,
24
+ provideModuleToComponent: () => x,
25
+ useComponentModule: () => m,
26
+ useInject: () => f,
27
+ useInjectMany: () => v
28
+ }), module.exports = (e = a, c(o({}, "__esModule", {
32
29
  value: !0
33
30
  }), e));
34
31
 
35
- var s = require("@adimm/x-injection"), c = require("react"), a = (0, c.createContext)(s.AppModule), d = (0,
36
- c.createContext)(new Map), l = require("react");
32
+ var d = require("@adimm/x-injection"), p = (0, require("react").createContext)(d.AppModule), l = require("react");
37
33
 
38
- function p(e) {
39
- const t = (0, l.useRef)(null);
40
- return null === t.current && (t.current = {
41
- value: e()
42
- }), t.current?.value;
34
+ function m() {
35
+ return (0, l.useContext)(p);
43
36
  }
44
37
 
45
- i(p, "useOnce");
46
-
47
- var m = require("react");
48
-
49
- function C(e) {
50
- const t = (0, m.useRef)(void 0), n = (0, m.useRef)(!1), r = (0, m.useRef)(!1), [, o] = (0,
51
- m.useState)(0);
52
- n.current && (r.current = !0), (0, m.useEffect)((() => (n.current || (t.current = e(),
53
- n.current = !0), o((e => e + 1)), () => {
54
- r.current && t.current?.();
55
- })), []);
38
+ function f(e, t) {
39
+ return m().get(e, t?.isOptional);
56
40
  }
57
41
 
58
- i(C, "useEffectOnce");
59
-
60
- var f = require("react");
61
-
62
- function O() {
63
- const [, e] = (0, f.useState)(0);
64
- return () => e((e => e + 1));
42
+ function v(...e) {
43
+ return m().getMany(...e);
65
44
  }
66
45
 
67
- i(O, "useRerender");
68
-
69
- var x = require("react");
70
-
71
- function M(e, t) {
72
- return (0, x.useContext)(a).ctx.get(e, t?.isOptional);
73
- }
74
-
75
- function v(e, t) {
76
- return p((() => M(e, t)));
77
- }
46
+ s(m, "useComponentModule"), s(f, "useInject"), s(v, "useInjectMany");
78
47
 
79
- i(M, "useInjectOnRender"), i(v, "useInject");
80
-
81
- var I = require("react");
48
+ var M = require("@adimm/x-injection"), C = class e extends M.ProviderModule {
49
+ static {
50
+ s(this, "ComponentProviderModule");
51
+ }
52
+ _initializedFromComponent;
53
+ constructor(e) {
54
+ super(M.ProviderModuleHelpers.buildInternalConstructorParams({
55
+ ...e,
56
+ defaultScope: e.defaultScope ?? M.InjectionScope.Singleton,
57
+ identifier: Symbol(`Component${e.identifier.description}`)
58
+ })), this._initializedFromComponent = !1;
59
+ }
60
+ toNaked() {
61
+ return this;
62
+ }
63
+ clone(t) {
64
+ let o = [ ...this.providers ];
65
+ t?.providersMap && (o = o.map((e => t.providersMap(e, this))));
66
+ const r = new e(M.ProviderModuleHelpers.buildInternalConstructorParams({
67
+ isAppModule: this.isAppModule,
68
+ identifier: Symbol(this.identifier.description.replace("Component", "")),
69
+ defaultScope: this.defaultScope.native,
70
+ dynamicExports: this.dynamicExports,
71
+ onReady: this.onReady,
72
+ onDispose: this.onDispose,
73
+ importedProvidersMap: t?.importedProvidersMap,
74
+ imports: [ ...this.imports ],
75
+ providers: o,
76
+ exports: [ ...this.exports ]
77
+ }));
78
+ return r._initializedFromComponent = this._initializedFromComponent, r;
79
+ }
80
+ dispose() {
81
+ this._dispose();
82
+ }
83
+ _createContextualizedComponentInstance() {
84
+ if (this._initializedFromComponent) return this;
85
+ const e = this.clone().toNaked();
86
+ return e.identifier = Symbol(`Contextualized${e.identifier.description}`), e._initializedFromComponent = !0,
87
+ e;
88
+ }
89
+ }, h = require("react"), y = require("react");
82
90
 
83
- function _({deps: e}) {
84
- return (0, I.useContext)(a).ctx.getMany(...e);
91
+ function P(e) {
92
+ const t = (0, y.useRef)(void 0), o = (0, y.useRef)(!1), r = (0, y.useRef)(!1), [, n] = (0,
93
+ y.useState)(0);
94
+ o.current && (r.current = !0), (0, y.useEffect)((() => (o.current || (t.current = e(),
95
+ o.current = !0), n((e => e + 1)), () => {
96
+ r.current && t.current?.();
97
+ })), []);
85
98
  }
86
99
 
87
- function R({deps: e, options: t}) {
88
- return p((() => _({
89
- options: t,
90
- deps: e
91
- })));
100
+ function j(e, t) {
101
+ const o = (0, h.useMemo)((() => (t ?? e).toNaked()._createContextualizedComponentInstance()), [ e, t ]);
102
+ return P((() => () => {
103
+ o.dispose();
104
+ })), o;
92
105
  }
93
106
 
94
- i(_, "useInjectManyOnRender"), i(R, "useInjectMany");
107
+ s(P, "useEffectOnce"), s(j, "useContextualizedModule");
95
108
 
96
- var E = require("react");
109
+ var b = require("@adimm/x-injection");
97
110
 
98
- function h() {
99
- const e = (0, E.useContext)(a);
100
- if (e.ctx.toNaked().isAppModule) return;
101
- (0, E.useContext)(d).set(e.ctx.toString(), e.ctx);
111
+ function _(e, t, o) {
112
+ const r = {
113
+ ...t
114
+ };
115
+ return ("object" == typeof e && "type" in e && (0, b.isFunction)(e.type) || (0,
116
+ b.isFunction)(e)) && (r.module = o), r;
102
117
  }
103
118
 
104
- i(h, "useExposeComponentModuleContext");
105
-
106
- var j = require("react");
107
-
108
- function y() {
109
- const e = (0, j.useContext)(a), t = (0, j.useContext)(d), n = O();
110
- (0, j.useEffect)((() => {
111
- const r = e.ctx.toNaked(), o = r.imports.map((e => {
112
- const n = e.toString();
113
- return t.get(n)?.toString() === n ? t.get(n) : e;
119
+ function x(e, t) {
120
+ return o => {
121
+ const r = j(e, o.module);
122
+ return React.createElement(p.Provider, {
123
+ value: r
124
+ }, React.createElement(E, {
125
+ module: r,
126
+ componentProps: o,
127
+ component: t
114
128
  }));
115
- o.length > 0 && (r._lazyInit({
116
- ...r._initialOptions,
117
- imports: o
118
- }), n());
119
- }), [ e, t ]);
129
+ };
120
130
  }
121
131
 
122
- i(y, "useRerenderOnChildrenModuleContextLoaded");
132
+ function E({module: e, component: t, componentProps: o}) {
133
+ return React.createElement(React.Fragment, null, t(_(t, o, e)));
134
+ }
123
135
 
124
- var g = require("react");
136
+ s(_, "forwardPropsWithModule"), s(x, "provideModuleToComponent"), s(E, "ComponentRenderer");
125
137
 
126
- function P({children: e, render: t, module: n, tryReInitModuleOnMount: r, disposeModuleOnUnmount: o}) {
127
- const i = n.toNaked().isAppModule, u = (0, g.useCallback)((() => t?.()), []), s = {
128
- ctx: i ? n : n.toNaked()._convertToContextualizedComponentInstance()
129
- };
130
- return React.createElement(a.Provider, {
131
- value: s
132
- }, React.createElement(N, {
133
- children: e ?? React.createElement(u, null),
134
- module: s,
135
- tryReInitModuleOnMount: r,
136
- disposeModuleOnUnmount: o
137
- }));
138
- }
138
+ var O = ((e, r, n) => (n = null != e ? t(i(e)) : {}, c(!r && e && e.__esModule ? n : o(n, "default", {
139
+ value: e,
140
+ enumerable: !0
141
+ }), e)))(require("react"), 1);
139
142
 
140
- function N({children: e, module: t, tryReInitModuleOnMount: n, disposeModuleOnUnmount: r = !1}) {
141
- return C((() => {
142
- const e = t.ctx.toNaked();
143
- return e.isDisposed && n && e._lazyInit(n), () => {
144
- r && !e.isDisposed && e._dispose();
145
- };
146
- })), e;
143
+ function I({module: e, children: t}) {
144
+ const o = t.props ?? {}, r = j(e, o.module);
145
+ return O.default.createElement(p.Provider, {
146
+ value: r
147
+ }, O.default.cloneElement(t, _(t, o, r)));
147
148
  }
148
149
 
149
- i(P, "ModuleProvider"), i(N, "XInjectionChildrenRenderer");
150
+ s(I, "ProvideModule");
150
151
 
151
- var S = require("@adimm/x-injection"), q = class e extends S.ProviderModule {
152
+ var g = require("react"), R = require("@adimm/x-injection"), F = class e extends R.XInjectionProviderModuleError {
152
153
  static {
153
- i(this, "ComponentProviderModule");
154
- }
155
- _initializedFromComponent;
156
- _initialOptions;
157
- constructor(e) {
158
- super(S.ProviderModuleHelpers.buildInternalConstructorParams({
159
- ...e,
160
- defaultScope: e.defaultScope ?? S.InjectionScope.Request,
161
- identifier: Symbol(`Component${e.identifier.description}`)
162
- })), this._initializedFromComponent = !1, this._initialOptions = e;
163
- }
164
- toNaked() {
165
- return this;
166
- }
167
- dispose() {
168
- this._dispose();
154
+ s(this, "XInjectionHookFactoryError");
169
155
  }
170
- _convertToContextualizedComponentInstance() {
171
- if (this.isAppModule || this.isDisposed) return this;
172
- const t = this._getProviders().map((e => (0, S.isClassOrFunction)(e) ? (0, S.isClass)(e) ? {
173
- scope: S.InjectionScope.Singleton,
174
- provide: e,
175
- useClass: e
176
- } : {
177
- provide: e,
178
- useValue: e
179
- } : {
180
- ...e,
181
- scope: S.InjectionScope.Singleton
182
- })), n = new e({
183
- ...this._initialOptions,
184
- providers: t
156
+ name=e.name;
157
+ };
158
+
159
+ function q({use: e, inject: t}) {
160
+ return o => {
161
+ const r = m(), n = (0, g.useMemo)((() => {
162
+ if (0 === t.length) throw new F(r, "The 'deps' property array is missing!");
163
+ return r.getMany(...t);
164
+ }), [ t ]);
165
+ return e({
166
+ ...o,
167
+ deps: [ ...n ]
185
168
  });
186
- return n._initializedFromComponent = !0, n;
187
- }
188
- }, T = require("react");
189
-
190
- function b({children: e, contextInstance: t}) {
191
- const n = (0, T.useMemo)((() => new Map), []);
192
- return React.createElement(d.Provider, {
193
- value: n
194
- }, React.createElement(k, {
195
- contextInstance: t
196
- }), e);
197
- }
198
-
199
- function k({contextInstance: e}) {
200
- const t = (0, T.useContext)(d);
201
- return (0, T.useEffect)((() => {
202
- const n = e?.(t);
203
- if (!n) return;
204
- const r = t.get(n.tryGet.toString());
205
- r && n.thenDo(r);
206
- }), [ t ]), null;
169
+ };
207
170
  }
208
171
 
209
- i(b, "TapIntoComponent"), i(k, "CtxExposer");//# sourceMappingURL=index.cjs.map
172
+ s(q, "hookFactory");//# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/core/react-context.ts","../src/helpers/hooks/use-once.ts","../src/helpers/hooks/use-effect-once.ts","../src/helpers/hooks/use-rerender.ts","../src/core/hooks/use-inject-on-render.ts","../src/core/hooks/use-inject.ts","../src/core/hooks/use-inject-many-on-render.ts","../src/core/hooks/use-inject-many.ts","../src/core/hooks/use-expose-component-module-context.ts","../src/core/hooks/use-rerender-on-children-module-context-loaded.ts","../src/core/providers/module-provider/module.provider.tsx","../src/core/component-provider-module.ts","../src/core/utils/tap-into-component-context/tap-into-component-context.tsx"],"sourcesContent":["export * from './core';\nexport type * from './types';\n","import { AppModule } from '@adimm/x-injection';\nimport { createContext } from 'react';\n\nimport type { IComponentProviderModule } from '../types';\n\n/**\n * The `React.Context` value to be provided to a `React.Provider`.\n *\n * Its default value is a reference to the {@link AppModule}.\n */\nexport const REACT_X_INJECTION_CONTEXT = createContext<{ ctx: IComponentProviderModule }>(AppModule as any);\n\nexport const REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT = createContext<Map<string, IComponentProviderModule>>(\n new Map()\n);\n","import { useRef } from 'react';\n\nexport function useOnce<T>(fn: () => T): T {\n const ref = useRef<OnceValue<T> | null>(null);\n\n if (ref.current === null) {\n ref.current = { value: fn() };\n }\n\n return ref.current?.value;\n}\n\ntype OnceValue<T> = { value: T };\n","import { useEffect, useRef, useState } from 'react';\n\n// Credits: https://stackoverflow.com/a/74000921\n\n/** Custom {@link useEffect} hook which will be run once. _(In `StrictMode` as well)_ */\nexport function useEffectOnce(effect: () => React.EffectCallback) {\n const destroyFunc = useRef<React.EffectCallback>(undefined);\n const effectCalled = useRef(false);\n const renderAfterCalled = useRef(false);\n const [, forceRerender] = useState(0);\n\n if (effectCalled.current) renderAfterCalled.current = true;\n\n useEffect(() => {\n // only execute the effect first time around\n if (!effectCalled.current) {\n destroyFunc.current = effect();\n effectCalled.current = true;\n }\n\n // this forces one render after the effect is run\n forceRerender((x) => x + 1);\n\n return () => {\n // if the comp didn't render since the useEffect was called,\n // we know it's the dummy React cycle\n if (!renderAfterCalled.current) return;\n\n destroyFunc.current?.();\n };\n }, []);\n}\n","import { useState } from 'react';\n\nexport function useRerender(): () => void {\n const [, setRerender] = useState(0);\n\n return () => setRerender((x) => x + 1);\n}\n","import type { ProviderToken } from '@adimm/x-injection';\nimport { useContext } from 'react';\n\nimport type { UseInjectSharedOptions } from '../../types';\nimport { REACT_X_INJECTION_CONTEXT } from '../react-context';\n\n/**\n * React `hook` which can be used inside a component to inject the required {@link provider | dependency}.\n *\n * **Note:** _By using this hook, the dependency will be injected on each re-render process._\n * _If you need to inject the dependency only once, you must use the `useInject` hook._\n * _It basically acts like a `Transient` scope, ensuring that a new dependency is injected on each re-render._\n *\n * @param provider The {@link ProviderToken}.\n * @param options See {@link UseInjectSharedOptions}.\n * @returns Either the {@link T | dependency} or `undefined` if {@link isOptional} is set to `true`.\n */\nexport function useInjectOnRender<T>(provider: ProviderToken<T>, options?: UseInjectOptions): T {\n const componentModule = useContext(REACT_X_INJECTION_CONTEXT);\n\n return componentModule.ctx.get(provider, options?.isOptional);\n}\n\nexport type UseInjectOptions = UseInjectSharedOptions & {\n /** When set to `false` _(default)_ an exception will be thrown when the `providerOrIdentifier` isn't bound. */\n isOptional?: boolean;\n};\n","import type { ProviderToken } from '@adimm/x-injection';\n\nimport { useOnce } from '../../helpers';\nimport { useInjectOnRender, type UseInjectOptions } from './use-inject-on-render';\n\n/**\n * React `hook` which can be used inside a component to inject the required {@link provider | dependency}.\n *\n * **Note:** _By using this hook, the dependency will be injected only once after the first component mount process._\n * _If you need to re-inject the dependency on each re-render, you must use the `useInjectOnRender` hook._\n * _It basically acts like a `Request` scope, ensuring that even a `Transient` dependency does not mutate during re-renders._\n *\n * @param provider The {@link ProviderToken}.\n * @param options See {@link UseInjectSharedOptions}.\n * @returns Either the {@link T | dependency} or `undefined` if {@link isOptional} is set to `true`.\n */\nexport function useInject<T>(provider: ProviderToken<T>, options?: UseInjectOptions): T {\n return useOnce(() => useInjectOnRender(provider, options));\n}\n","import type {\n ProviderModuleGetManyParam,\n ProviderModuleGetManySignature,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n ProviderToken,\n} from '@adimm/x-injection';\nimport { useContext } from 'react';\n\nimport type { UseInjectSharedOptions } from '../../types';\nimport { REACT_X_INJECTION_CONTEXT } from '../react-context';\n\n/**\n * Can be used to retrieve many resolved `dependencies` from the module container at once.\n *\n * **Note:** _By using this hook, the dependencies will be injected on each re-render process._\n * _If you need to inject the dependencies only once, you must use the `useInjectMany` hook._\n *\n * @param options See {@link UseInjectSharedOptions}.\n * @param deps Either one or more {@link ProviderToken}.\n * @returns Tuple containing the {@link D | dependencies}.\n */\nexport function useInjectManyOnRender<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>({\n deps,\n}: {\n deps: [...(D | unknown[])];\n options?: UseInjectSharedOptions;\n}): ProviderModuleGetManySignature<D> {\n const componentModule = useContext(REACT_X_INJECTION_CONTEXT);\n\n return componentModule.ctx.getMany(...deps);\n}\n","import type { ProviderModuleGetManyParam, ProviderModuleGetManySignature, ProviderToken } from '@adimm/x-injection';\n\nimport { useOnce } from '../../helpers';\nimport type { UseInjectSharedOptions } from '../../types';\nimport { useInjectManyOnRender } from './use-inject-many-on-render';\n\n/**\n * Can be used to retrieve many resolved `dependencies` from the module container at once.\n *\n * **Note:** _By using this hook, the dependencies will be injected only once after the first component mount process._\n * _If you need to re-inject the dependencies on each re-render, you must use the `useInjectManyOnRender` hook._\n *\n * @param options See {@link UseInjectSharedOptions}.\n * @param deps Either one or more {@link ProviderToken}.\n * @returns Tuple containing the {@link D | dependencies}.\n */\nexport function useInjectMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>({\n deps,\n options,\n}: {\n deps: [...(D | unknown[])];\n options?: UseInjectSharedOptions;\n}): ProviderModuleGetManySignature<D> {\n return useOnce(() => useInjectManyOnRender({ options, deps }));\n}\n","import { useContext } from 'react';\n\nimport { REACT_X_INJECTION_CONTEXT, REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT } from '../react-context';\n\nexport function useExposeComponentModuleContext(): void {\n const componentModule = useContext(REACT_X_INJECTION_CONTEXT);\n if (componentModule.ctx.toNaked().isAppModule) return;\n\n const exposed = useContext(REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT);\n\n exposed.set(componentModule.ctx.toString(), componentModule.ctx);\n}\n","import { useContext, useEffect } from 'react';\n\nimport { useRerender } from '../../helpers';\nimport type { IComponentProviderModuleNaked } from '../../types';\nimport { REACT_X_INJECTION_CONTEXT, REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT } from '../react-context';\n\n/**\n * This is an **experimental** hook which can be used to make sure that a component will re-render when a children\n * exposes its internal context module.\n *\n * It works best with the `useInjectOnRender` hook, as it'll re-resolve all the required dependencies\n * of the injected ProviderToken.\n *\n * **Use it carefully as it may lead to unnecessary re-render cycles or it may even not work as expected!**\n * **It's safer to use the `TapIntoComponent` wrapper component with the `contextInstance` to manually inject the**\n * **contextualized dependencies of the children into a parent component service!**\n *\n * @experimental\n */\nexport function useRerenderOnChildrenModuleContextLoaded(): void {\n const parentModule = useContext(REACT_X_INJECTION_CONTEXT);\n const ctxMap = useContext(REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT);\n\n const rerenderComponent = useRerender();\n\n useEffect(() => {\n const parentModuleNaked = parentModule.ctx.toNaked();\n\n const contextualizedImportedModules = parentModuleNaked.imports.map((importedModule) => {\n const importedModuleId = importedModule.toString();\n\n const shouldReplaceImportedModuleWithContextualized =\n ctxMap.get(importedModuleId)?.toString() === importedModuleId;\n\n /* istanbul ignore next */\n if (!shouldReplaceImportedModuleWithContextualized)\n return importedModule as unknown as IComponentProviderModuleNaked;\n\n return ctxMap.get(importedModuleId) as IComponentProviderModuleNaked;\n });\n\n if (contextualizedImportedModules.length > 0) {\n parentModuleNaked._lazyInit({\n ...parentModuleNaked._initialOptions,\n imports: contextualizedImportedModules,\n });\n\n rerenderComponent();\n }\n }, [parentModule, ctxMap]);\n}\n","import { useCallback } from 'react';\nimport type { Except } from 'type-fest';\n\nimport { useEffectOnce } from '../../../helpers';\nimport type { IComponentProviderModule } from '../../../types';\nimport { REACT_X_INJECTION_CONTEXT } from '../../react-context';\nimport type { ModuleProviderProps } from './models';\n\nexport function ModuleProvider({\n children,\n render,\n module,\n tryReInitModuleOnMount,\n disposeModuleOnUnmount,\n}: ModuleProviderProps) {\n const isAppModule = module.toNaked().isAppModule;\n const Renderer = useCallback(() => render?.(), []);\n\n const moduleCtxReference = {\n ctx: isAppModule ? module : module.toNaked()._convertToContextualizedComponentInstance(),\n };\n\n return (\n <REACT_X_INJECTION_CONTEXT.Provider value={moduleCtxReference}>\n <XInjectionChildrenRenderer\n children={children ?? <Renderer />}\n module={moduleCtxReference}\n tryReInitModuleOnMount={tryReInitModuleOnMount}\n disposeModuleOnUnmount={disposeModuleOnUnmount}\n />\n </REACT_X_INJECTION_CONTEXT.Provider>\n );\n}\n\nfunction XInjectionChildrenRenderer({\n children,\n module,\n tryReInitModuleOnMount,\n disposeModuleOnUnmount = false,\n}: Except<ModuleProviderProps, 'module'> & { module: { ctx: IComponentProviderModule } }) {\n // We use the `useEffectOnce` custom hook in order\n // to make sure that if the developer is providing the\n // `tryReInitModuleOnMount` and/or `disposeModuleOnUnmount` options\n // we do not early dispose the module when React double re-renders the\n // component while StrictMode is enabled.\n // This hook guarantees that the same behavior is expected with or without StrictMode.\n //\n // https://react.dev/reference/react/StrictMode\n useEffectOnce(() => {\n // ON MOUNT\n\n const moduleNaked = module.ctx.toNaked();\n\n /* istanbul ignore next */\n if (moduleNaked.isDisposed && tryReInitModuleOnMount) {\n /* istanbul ignore next */\n moduleNaked._lazyInit(tryReInitModuleOnMount);\n }\n\n return () => {\n // ON UNMOUNT\n\n if (!disposeModuleOnUnmount || moduleNaked.isDisposed) return;\n\n moduleNaked._dispose();\n };\n });\n\n return children;\n}\n","import {\n InjectionScope,\n isClass,\n isClassOrFunction,\n ProviderModule,\n ProviderModuleHelpers,\n type DependencyProvider,\n type IProviderModuleNaked,\n type ProviderClassToken,\n type ProviderModuleOptions,\n type ProviderValueToken,\n} from '@adimm/x-injection';\n\nimport type { IComponentProviderModule, IComponentProviderModuleNaked } from '../types';\n\n/** A superset of the {@link ProviderModule} used to integrate within a `React` component. */\nexport class ComponentProviderModule extends ProviderModule implements IComponentProviderModule {\n protected readonly _initializedFromComponent: IComponentProviderModuleNaked['_initializedFromComponent'];\n protected readonly _initialOptions: IComponentProviderModuleNaked['_initialOptions'];\n\n constructor(options: ProviderModuleOptions) {\n super(\n ProviderModuleHelpers.buildInternalConstructorParams({\n ...options,\n // By default components should have all their providers\n // defined as transient because a component may have more than one instance of itself.\n defaultScope: options.defaultScope ?? InjectionScope.Request,\n identifier: Symbol(`Component${options.identifier.description}`),\n })\n );\n\n this._initializedFromComponent = false;\n this._initialOptions = options;\n }\n\n override toNaked(): IComponentProviderModuleNaked & IProviderModuleNaked {\n return this as any;\n }\n\n /* istanbul ignore next */\n dispose(): void {\n this._dispose();\n }\n\n /**\n * **Publicly visible when the instance is casted to {@link IComponentProviderModuleNaked}.**\n *\n * See {@link IComponentProviderModuleNaked._convertToContextualizedComponentInstance}.\n */\n /* istanbul ignore next */\n protected _convertToContextualizedComponentInstance(): IComponentProviderModule {\n if (this.isAppModule || this.isDisposed) return this;\n\n const contextualizedProviders = this._getProviders().map((provider) => {\n if (!isClassOrFunction(provider)) {\n return {\n ...provider,\n scope: InjectionScope.Singleton,\n } as DependencyProvider;\n }\n\n if (isClass(provider)) {\n return {\n scope: InjectionScope.Singleton,\n provide: provider,\n useClass: provider,\n } as ProviderClassToken<any>;\n }\n\n return {\n provide: provider,\n useValue: provider,\n } as ProviderValueToken<any>;\n });\n\n const componentModule = new ComponentProviderModule({\n ...this._initialOptions,\n providers: contextualizedProviders,\n });\n\n //@ts-expect-error Read-only property.\n componentModule._initializedFromComponent = true;\n\n return componentModule;\n }\n}\n","import { useContext, useEffect, useMemo } from 'react';\nimport type { Except } from 'type-fest';\n\nimport { REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT } from '../../react-context';\nimport type { TapIntoComponentContextProps } from './interfaces';\n\n/**\n * This component is the standard way to \"tap into\" an instance of the component\n * in order to get access to its scoped module container and its _(exposed)_ dependencies _instances_.\n *\n * @param contextInstance See {@link TapIntoComponentContextProps.contextInstance}.\n * @param exposed See {@link TapIntoComponentContextProps.exposed}.\n */\nexport function TapIntoComponent({ children, contextInstance }: TapIntoComponentContextProps) {\n const moduleContextMap = useMemo(() => new Map(), []);\n\n return (\n <REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT.Provider value={moduleContextMap}>\n <CtxExposer contextInstance={contextInstance} />\n {children}\n </REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT.Provider>\n );\n}\n\nfunction CtxExposer({ contextInstance }: Except<TapIntoComponentContextProps, 'children'>) {\n const ctxMap = useContext(REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT);\n\n useEffect(() => {\n const fluidSyntax = contextInstance?.(ctxMap);\n if (!fluidSyntax) return;\n\n const moduleCtx = ctxMap.get(fluidSyntax.tryGet.toString());\n /* istanbul ignore next */\n if (!moduleCtx) return;\n\n fluidSyntax.thenDo(moduleCtx);\n }, [ctxMap]);\n\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;ACAA,yBAA0B;AAC1B,mBAA8B;AASvB,IAAMA,gCAA4BC,4BAAiDC,4BAAAA;AAEnF,IAAMC,yDAAqDF,4BAChE,oBAAIG,IAAAA,CAAAA;;;ACbN,IAAAC,gBAAuB;AAEhB,SAASC,QAAWC,IAAW;AACpC,QAAMC,UAAMC,sBAA4B,IAAA;AAExC,MAAID,IAAIE,YAAY,MAAM;AACxBF,QAAIE,UAAU;MAAEC,OAAOJ,GAAAA;IAAK;EAC9B;AAEA,SAAOC,IAAIE,SAASC;AACtB;AARgBL;;;ACFhB,IAAAM,gBAA4C;AAKrC,SAASC,cAAcC,QAAkC;AAC9D,QAAMC,kBAAcC,sBAA6BC,MAAAA;AACjD,QAAMC,mBAAeF,sBAAO,KAAA;AAC5B,QAAMG,wBAAoBH,sBAAO,KAAA;AACjC,QAAM,CAAA,EAAGI,aAAAA,QAAiBC,wBAAS,CAAA;AAEnC,MAAIH,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A,IAAAE,iBAA+C;AAaxC,SAASC,iBAAiB,EAAEC,UAAUC,gBAAe,GAAgC;AAC1F,QAAMC,uBAAmBC,wBAAQ,MAAM,oBAAIC,IAAAA,GAAO,CAAA,CAAE;AAEpD,SACE,sBAAA,cAACC,mDAAmDC,UAAQ;IAACC,OAAOL;KAClE,sBAAA,cAACM,YAAAA;IAAWP;MACXD,QAAAA;AAGP;AATgBD;AAWhB,SAASS,WAAW,EAAEP,gBAAe,GAAoD;AACvF,QAAMQ,aAASC,2BAAWL,kDAAAA;AAE1BM,gCAAU,MAAA;AACR,UAAMC,cAAcX,kBAAkBQ,MAAAA;AACtC,QAAI,CAACG,YAAa;AAElB,UAAMC,YAAYJ,OAAOK,IAAIF,YAAYG,OAAOC,SAAQ,CAAA;AAExD,QAAI,CAACH,UAAW;AAEhBD,gBAAYK,OAAOJ,SAAAA;EACrB,GAAG;IAACJ;GAAO;AAEX,SAAO;AACT;AAfSD;","names":["REACT_X_INJECTION_CONTEXT","createContext","AppModule","REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT","Map","import_react","useOnce","fn","ref","useRef","current","value","import_react","useEffectOnce","effect","destroyFunc","useRef","undefined","effectCalled","renderAfterCalled","forceRerender","useState","current","useEffect","x","import_react","useRerender","setRerender","useState","x","import_react","useInjectOnRender","provider","options","componentModule","useContext","REACT_X_INJECTION_CONTEXT","ctx","get","isOptional","useInject","provider","options","useOnce","useInjectOnRender","import_react","useInjectManyOnRender","deps","componentModule","useContext","REACT_X_INJECTION_CONTEXT","ctx","getMany","useInjectMany","deps","options","useOnce","useInjectManyOnRender","import_react","useExposeComponentModuleContext","componentModule","useContext","REACT_X_INJECTION_CONTEXT","ctx","toNaked","isAppModule","exposed","REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT","set","toString","import_react","useRerenderOnChildrenModuleContextLoaded","parentModule","useContext","REACT_X_INJECTION_CONTEXT","ctxMap","REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT","rerenderComponent","useRerender","useEffect","parentModuleNaked","ctx","toNaked","contextualizedImportedModules","imports","map","importedModule","importedModuleId","toString","shouldReplaceImportedModuleWithContextualized","get","length","_lazyInit","_initialOptions","import_react","ModuleProvider","children","render","module","tryReInitModuleOnMount","disposeModuleOnUnmount","isAppModule","toNaked","Renderer","useCallback","moduleCtxReference","ctx","_convertToContextualizedComponentInstance","REACT_X_INJECTION_CONTEXT","Provider","value","XInjectionChildrenRenderer","useEffectOnce","moduleNaked","isDisposed","_lazyInit","_dispose","import_x_injection","ComponentProviderModule","ProviderModule","_initializedFromComponent","_initialOptions","constructor","options","ProviderModuleHelpers","buildInternalConstructorParams","defaultScope","InjectionScope","Request","identifier","Symbol","description","toNaked","dispose","_dispose","_convertToContextualizedComponentInstance","isAppModule","isDisposed","contextualizedProviders","_getProviders","map","provider","isClassOrFunction","scope","Singleton","isClass","provide","useClass","useValue","componentModule","providers","import_react","TapIntoComponent","children","contextInstance","moduleContextMap","useMemo","Map","REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT","Provider","value","CtxExposer","ctxMap","useContext","useEffect","fluidSyntax","moduleCtx","get","tryGet","toString","thenDo"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/core/react-context.ts","../src/core/hooks/use-component-module.ts","../src/core/hooks/use-inject.ts","../src/core/hooks/use-inject-many.ts","../src/core/component-provider-module.ts","../src/helpers/hooks/use-contextualized-module.ts","../src/helpers/hooks/use-effect-once.ts","../src/helpers/forward-props-with-module.ts","../src/core/provide-module/provide-module.arrow-function.tsx","../src/core/provide-module/provide-module.provider.tsx","../src/core/hook-factory.ts","../src/errors/hook-factory.ts"],"sourcesContent":["export * from './core';\nexport type * from './types';\n","import { AppModule } from '@adimm/x-injection';\nimport { createContext } from 'react';\n\nimport type { IComponentProviderModule } from '../types';\n\nexport const REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT = createContext<IComponentProviderModule>(AppModule as any);\n","import { useContext } from 'react';\n\nimport type { IComponentProviderModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\n/** Can be used to retrieve the {@link IComponentProviderModule} from the current context. */\nexport function useComponentModule(): IComponentProviderModule {\n return useContext(REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT);\n}\n","import type { ProviderToken } from '@adimm/x-injection';\n\nimport { useComponentModule } from './use-component-module';\n\n/**\n * Low-level hook which can be used to resolve a single dependency from the current\n * context module.\n *\n * **Note:** _In order to better modularize your code-base, you should strive to create custom hooks by using the_\n * _`hookFactory` method to compose a custom hook._\n *\n * @param provider The {@link ProviderToken}.\n * @param options See {@link UseInjectOptions}.\n * @returns The resolved {@link T | dependency}.\n */\nexport function useInject<T>(provider: ProviderToken<T>, options?: UseInjectOptions): T {\n const componentModule = useComponentModule();\n\n return componentModule.get(provider, options?.isOptional);\n}\n\nexport type UseInjectOptions = {\n /** When set to `false` _(default)_ an exception will be thrown when the `providerOrIdentifier` isn't bound. */\n isOptional?: boolean;\n};\n","import type { ProviderModuleGetManyParam, ProviderModuleGetManySignature, ProviderToken } from '@adimm/x-injection';\n\nimport { useComponentModule } from './use-component-module';\n\n/**\n * Low-level hook which can be used to resolve multiple dependencies at once from the current\n * context module.\n *\n * **Note:** _In order to better modularize your code-base, you should strive to create custom hooks by using the_\n * _`hookFactory` method to compose a custom hook._\n *\n * @param deps Either one or more {@link ProviderToken}.\n * @returns Tuple containing the {@link D | dependencies}.\n */\nexport function useInjectMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>(\n ...deps: D | unknown[]\n): ProviderModuleGetManySignature<D> {\n const componentModule = useComponentModule();\n\n return componentModule.getMany(...deps);\n}\n","import {\n InjectionScope,\n ProviderModule,\n ProviderModuleHelpers,\n type CloneParams,\n type IProviderModuleNaked,\n type ProviderModuleOptions,\n} from '@adimm/x-injection';\n\nimport type { IComponentProviderModule, IComponentProviderModuleNaked } from '../types';\n\n/** A superset of the {@link ProviderModule} used to integrate within a `React` component. */\nexport class ComponentProviderModule extends ProviderModule implements IComponentProviderModule {\n protected readonly _initializedFromComponent: IComponentProviderModuleNaked['_initializedFromComponent'];\n\n constructor(options: ProviderModuleOptions) {\n super(\n ProviderModuleHelpers.buildInternalConstructorParams({\n ...options,\n defaultScope: options.defaultScope ?? InjectionScope.Singleton,\n identifier: Symbol(`Component${options.identifier.description}`),\n })\n );\n\n this._initializedFromComponent = false;\n }\n\n override toNaked(): IComponentProviderModuleNaked & IProviderModuleNaked {\n return this as any;\n }\n\n /* istanbul ignore next */\n override clone(options?: CloneParams): IComponentProviderModule {\n let providers = [...this.providers];\n\n if (options?.providersMap) {\n providers = providers.map((provider) => options.providersMap!(provider, this));\n }\n\n const clonedModule = new ComponentProviderModule(\n ProviderModuleHelpers.buildInternalConstructorParams({\n isAppModule: this.isAppModule,\n identifier: Symbol(this.identifier.description!.replace('Component', '')),\n defaultScope: this.defaultScope.native,\n dynamicExports: this.dynamicExports,\n onReady: this.onReady,\n onDispose: this.onDispose,\n importedProvidersMap: options?.importedProvidersMap,\n imports: [...this.imports],\n providers,\n exports: [...this.exports],\n })\n );\n\n //@ts-expect-error Read-only method.\n clonedModule._initializedFromComponent = this._initializedFromComponent;\n\n return clonedModule;\n }\n\n /* istanbul ignore next */\n dispose(): void {\n this._dispose();\n }\n\n //#region IComponentProviderModuleNaked methods\n\n /**\n * **Publicly visible when the instance is casted to {@link IComponentProviderModuleNaked}.**\n *\n * See {@link IComponentProviderModuleNaked._createContextualizedComponentInstance}.\n */\n protected _createContextualizedComponentInstance(): IComponentProviderModule {\n if (this._initializedFromComponent) return this;\n\n const ctxModule = this.clone().toNaked();\n\n //@ts-expect-error Read-only property\n ctxModule.identifier = Symbol(`Contextualized${ctxModule.identifier.description}`);\n ctxModule._initializedFromComponent = true;\n\n return ctxModule;\n }\n\n //#endregion\n}\n","import { useMemo } from 'react';\n\nimport type { IComponentProviderModule } from '../../types';\nimport { useEffectOnce } from './use-effect-once';\n\nexport function useContextualizedModule(\n originalModule: IComponentProviderModule,\n forwardedModule?: IComponentProviderModule\n): IComponentProviderModule {\n const ctxModule = useMemo(() => {\n return (forwardedModule ?? originalModule).toNaked()._createContextualizedComponentInstance();\n }, [originalModule, forwardedModule]);\n\n useEffectOnce(() => {\n return () => {\n ctxModule.dispose();\n };\n });\n\n return ctxModule;\n}\n","import { useEffect, useRef, useState } from 'react';\n\n// Credits: https://stackoverflow.com/a/74000921\n\n/** Custom {@link useEffect} hook which will be run once. _(In `StrictMode` as well)_ */\nexport function useEffectOnce(effect: () => React.EffectCallback) {\n const destroyFunc = useRef<React.EffectCallback>(undefined);\n const effectCalled = useRef(false);\n const renderAfterCalled = useRef(false);\n const [, forceRerender] = useState(0);\n\n if (effectCalled.current) renderAfterCalled.current = true;\n\n useEffect(() => {\n // only execute the effect first time around\n if (!effectCalled.current) {\n destroyFunc.current = effect();\n effectCalled.current = true;\n }\n\n // this forces one render after the effect is run\n forceRerender((x) => x + 1);\n\n return () => {\n // if the comp didn't render since the useEffect was called,\n // we know it's the dummy React cycle\n if (!renderAfterCalled.current) return;\n\n destroyFunc.current?.();\n };\n }, []);\n}\n","import { isFunction } from '@adimm/x-injection';\n\nimport type { ReactElementWithProviderModule } from '../core';\nimport type { IComponentProviderModule, PropsWithModule } from '../types';\n\nexport function forwardPropsWithModule<P extends Record<string, any>>(\n component: ReactElementWithProviderModule<P> | React.ReactElement,\n props: Record<string, any>,\n module: IComponentProviderModule\n): PropsWithModule<P> {\n const isReactElement = typeof component === 'object' && 'type' in component;\n\n const result = {\n ...props,\n } as any;\n\n if ((isReactElement && isFunction(component.type)) || isFunction(component)) {\n result['module'] = module;\n }\n\n return result;\n}\n","import { forwardPropsWithModule, useContextualizedModule } from '../../helpers';\nimport type { IComponentProviderModule, PropsWithModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\n/**\n * Can be used to easily provide a {@link module} to any component.\n *\n * @example\n * ```tsx\n * interface MyComponentProps {\n * firstName: string;\n * lastName: string;\n * }\n *\n * export const MyComponent = provideModuleToComponent(\n * MyComponentModule,\n * ({ firstName, lastName }: MyComponentProps) => {\n * const service = useInject(MyComponentService);\n *\n * return <h1>Hello {service.computeUserName(firstName, lastName)}!</h1>\n * }\n * );\n *\n * function App() {\n * return <MyComponent firstName={'John'} lastName={'Doe'} />;\n * }\n * ```\n *\n * @param module The {@link IComponentProviderModule | Module} which should be consumed by the {@link component}.\n * @returns The provided {@link toComponent | Component}.\n */\nexport function provideModuleToComponent<\n P extends Record<string, any>,\n C extends ReactElementWithProviderModule<P> = ReactElementWithProviderModule<P>,\n>(module: IComponentProviderModule, component: ReactElementWithProviderModule<P>): C {\n return ((componentProps: PropsWithModule<P>) => {\n const moduleCtx = useContextualizedModule(module, componentProps.module);\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n <ComponentRenderer module={moduleCtx} componentProps={componentProps} component={component} />\n </REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider>\n );\n }) as any;\n}\n\nfunction ComponentRenderer<P extends Record<string, any>>({\n module,\n component,\n componentProps,\n}: {\n module: IComponentProviderModule;\n component: ReactElementWithProviderModule<P>;\n componentProps: P;\n}) {\n return <>{component(forwardPropsWithModule(component, componentProps, module))}</>;\n}\n\nexport type ReactElementWithProviderModule<P extends Record<string, any>> = (p: PropsWithModule<P>) => React.ReactNode;\n","import React from 'react';\n\nimport { forwardPropsWithModule, useContextualizedModule } from '../../helpers';\nimport type { IComponentProviderModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\n/**\n * Can be used to easily provide a {@link module} to any component.\n *\n * @example\n * ```tsx\n * interface MyComponentProps {\n * firstName: string;\n * lastName: string;\n * }\n *\n * function MyComponent({ firstName, lastName }: MyComponentProps) {\n * const service = useInject(MyComponentService);\n *\n * return <h1>Hello {service.computeUserName(firstName, lastName)}!</h1>\n * }\n *\n * function App() {\n * return (\n * <ProvideModule module={MyComponentModule}>\n * <MyComponent firstName={'John'} lastName={'Doe'} />\n * </ProvideModule>\n * );\n * }\n * ```\n *\n * @param param0 See {@link ProvideModuleFunctionParams}.\n * @returns The provided {@link toComponent | Component}.\n */\nexport function ProvideModule({ module, children }: ProvideModuleFunctionParams) {\n /* istanbul ignore next */\n const componentProps = (children.props ?? {}) as any;\n const moduleCtx = useContextualizedModule(module, componentProps.module);\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n {React.cloneElement(children, forwardPropsWithModule(children, componentProps, moduleCtx))}\n </REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider>\n );\n}\n\nexport interface ProvideModuleFunctionParams {\n /** The {@link IComponentProviderModule | Module} which should be consumed by the {@link children | component}. */\n module: IComponentProviderModule;\n\n children: React.ReactElement;\n}\n","import type { ProviderToken } from '@adimm/x-injection';\nimport { useMemo } from 'react';\n\nimport { XInjectionHookFactoryError } from '../errors';\nimport { useComponentModule } from './hooks';\n\nexport function hookFactory<P extends HookParams, D extends any[], T>({\n use: hook,\n inject,\n}: HookFactoryParams<P, D, T>): (p: P) => T {\n return (p: P) => {\n const componentModule = useComponentModule();\n\n const deps = useMemo(() => {\n if (inject.length === 0) {\n throw new XInjectionHookFactoryError(componentModule, `The 'deps' property array is missing!`);\n }\n\n return componentModule.getMany(...inject);\n }, [inject]);\n\n return hook({ ...p, deps: [...deps] } as any);\n };\n}\n\nexport interface HookFactoryParams<P extends HookParams, D extends any[], T> {\n use: HookWithProviderModuleDependencies<P, D, T>;\n inject: ProviderToken[];\n}\n\nexport type HookWithProviderModuleDependencies<P extends HookParams, D extends any[], T> = (p: HookWithDeps<P, D>) => T;\n\nexport type HookWithDeps<P extends HookParams, D extends any[]> = P & {\n /** Array containing the resolved dependencies from the component context. */\n deps: D;\n};\n\ntype HookParams = Record<string, any> | void;\n","import { XInjectionProviderModuleError } from '@adimm/x-injection';\n\nexport class XInjectionHookFacto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A2BE;AACpC;;;ADEO,SAASC,YAAsD,EACpEC,KAAKC,MACLC,OAAM,GACqB;AAC3B,SAAO,CAACC,MAAAA;AACN,UAAMC,kBAAkBC,mBAAAA;AAExB,UAAMC,WAAOC,uBAAQ,MAAA;AACnB,UAAIL,OAAOM,WAAW,GAAG;AACvB,cAAM,IAAIC,2BAA2BL,iBAAiB,uCAAuC;MAC/F;AAEA,aAAOA,gBAAgBM,QAAO,GAAIR,MAAAA;IACpC,GAAG;MAACA;KAAO;AAEX,WAAOD,KAAK;MAAE,GAAGE;MAAGG,MAAM;WAAIA;;IAAM,CAAA;EACtC;AACF;AAjBgBP;","names":["REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","createContext","AppModule","import_react","useComponentModule","useContext","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","useInject","provider","options","componentModule","useComponentModule","get","isOptional","useInjectMany","deps","componentModule","useComponentModule","getMany","import_x_injection","ComponentProviderModule","ProviderModule","_initializedFromComponent","constructor","options","ProviderModuleHelpers","buildInternalConstructorParams","defaultScope","InjectionScope","Singleton","identifier","Symbol","description","toNaked","clone","providers","providersMap","map","provider","clonedModule","isAppModule","replace","native","dynamicExports","onReady","onDispose","importedProvidersMap","imports","exports","dispose","_dispose","_createContextualizedComponentInstance","ctxModule","import_react","import_react","useEffectOnce","effect","destroyFunc","useRef","undefined","effectCalled","renderAfterCalled","forceRerender","useState","current","useEffect","x","useContextualizedModule","originalModule","forwardedModule","ctxModule","useMemo","toNaked","_createContextualizedComponentInstance","useEffectOnce","dispose","import_x_injection","forwardPropsWithModule","component","props","module","isReactElement","result","isFunction","type","provideModuleToComponent","module","component","componentProps","moduleCtx","useContextualizedModule","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","ComponentRenderer","forwardPropsWithModule","import_react","ProvideModule","module","children","componentProps","props","moduleCtx","useContextualizedModule","React","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","cloneElement","forwardPropsWithModule","import_react","import_x_injection","XInjectionHookFactoryError","XInjectionProviderModuleError","name","hookFactory","use","hook","inject","p","componentModule","useComponentModule","deps","useMemo","length","XInjectionHookFactoryError","getMany"]}