@adimm/x-injection-reactjs 0.1.1 → 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.d.ts CHANGED
@@ -1,18 +1,16 @@
1
- import { ProviderModuleOptions, IProviderModule, IProviderModuleNaked, ProviderToken, ProviderModuleGetManyParam, ProviderModuleGetManySignature, ProviderModule } from '@adimm/x-injection';
2
1
  import * as react from 'react';
2
+ import react__default from 'react';
3
+ import { IProviderModule, IProviderModuleNaked, ProviderToken, ProviderModuleGetManyParam, ProviderModuleGetManySignature, ProviderModule, ProviderModuleOptions, CloneParams } from '@adimm/x-injection';
3
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
5
 
5
6
  interface IComponentProviderModuleNaked extends IComponentProviderModule {
6
7
  /** Indicates if this module has been initialized by a React Component or not. */
7
8
  _initializedFromComponent: boolean;
8
- /** The {@link ProviderModuleOptions | options} with which the module has been originally initialized. */
9
- _initialOptions: ProviderModuleOptions;
10
9
  /**
11
- * Instantiate a new {@link IComponentProviderModule} which will be supplied to the React Component.
12
- *
13
- * All the `providers` will be injected into a `singleton` scope.
10
+ * It is used internally by the `ProviderModule` to create a new cloned
11
+ * module which will be consumed only by that specific component instance.
14
12
  */
15
- _convertToContextualizedComponentInstance(): IComponentProviderModule;
13
+ _createContextualizedComponentInstance(): IComponentProviderModule;
16
14
  }
17
15
 
18
16
  interface IComponentProviderModule extends IProviderModule {
@@ -30,217 +28,140 @@ interface IComponentProviderModule extends IProviderModule {
30
28
  dispose(): void;
31
29
  }
32
30
 
33
- interface UseInjectSharedOptions {
34
- }
31
+ type PropsWithModule<P extends Record<string, any>> = P & {
32
+ /**
33
+ * The {@link IComponentProviderModule | Module} which this component should consume.
34
+ *
35
+ * **Note:** _You can easily override this in your unit tests to provide a module having mocked providers_
36
+ * _without the need to create a new mocked component by using the composable `ProvideModule` method._
37
+ */
38
+ module?: IComponentProviderModule;
39
+ };
40
+
41
+ declare const REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT: react.Context<IComponentProviderModule>;
35
42
 
36
43
  /**
37
- * React `hook` which can be used inside a component to inject the required {@link provider | dependency}.
44
+ * Low-level hook which can be used to resolve a single dependency from the current
45
+ * context module.
38
46
  *
39
- * **Note:** _By using this hook, the dependency will be injected on each re-render process._
40
- * _If you need to inject the dependency only once, you must use the `useInject` hook._
41
- * _It basically acts like a `Transient` scope, ensuring that a new dependency is injected on each re-render._
47
+ * **Note:** _In order to better modularize your code-base, you should strive to create custom hooks by using the_
48
+ * _`hookFactory` method to compose a custom hook._
42
49
  *
43
50
  * @param provider The {@link ProviderToken}.
44
- * @param options See {@link UseInjectSharedOptions}.
45
- * @returns Either the {@link T | dependency} or `undefined` if {@link isOptional} is set to `true`.
51
+ * @param options See {@link UseInjectOptions}.
52
+ * @returns The resolved {@link T | dependency}.
46
53
  */
47
- declare function useInjectOnRender<T>(provider: ProviderToken<T>, options?: UseInjectOptions): T;
48
- type UseInjectOptions = UseInjectSharedOptions & {
54
+ declare function useInject<T>(provider: ProviderToken<T>, options?: UseInjectOptions): T;
55
+ type UseInjectOptions = {
49
56
  /** When set to `false` _(default)_ an exception will be thrown when the `providerOrIdentifier` isn't bound. */
50
57
  isOptional?: boolean;
51
58
  };
52
59
 
53
60
  /**
54
- * React `hook` which can be used inside a component to inject the required {@link provider | dependency}.
61
+ * Low-level hook which can be used to resolve multiple dependencies at once from the current
62
+ * context module.
55
63
  *
56
- * **Note:** _By using this hook, the dependency will be injected only once after the first component mount process._
57
- * _If you need to re-inject the dependency on each re-render, you must use the `useInjectOnRender` hook._
58
- * _It basically acts like a `Request` scope, ensuring that even a `Transient` dependency does not mutate during re-renders._
64
+ * **Note:** _In order to better modularize your code-base, you should strive to create custom hooks by using the_
65
+ * _`hookFactory` method to compose a custom hook._
59
66
  *
60
- * @param provider The {@link ProviderToken}.
61
- * @param options See {@link UseInjectSharedOptions}.
62
- * @returns Either the {@link T | dependency} or `undefined` if {@link isOptional} is set to `true`.
63
- */
64
- declare function useInject<T>(provider: ProviderToken<T>, options?: UseInjectOptions): T;
65
-
66
- /**
67
- * Can be used to retrieve many resolved `dependencies` from the module container at once.
68
- *
69
- * **Note:** _By using this hook, the dependencies will be injected only once after the first component mount process._
70
- * _If you need to re-inject the dependencies on each re-render, you must use the `useInjectManyOnRender` hook._
71
- *
72
- * @param options See {@link UseInjectSharedOptions}.
73
67
  * @param deps Either one or more {@link ProviderToken}.
74
68
  * @returns Tuple containing the {@link D | dependencies}.
75
69
  */
76
- declare function useInjectMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>({ deps, options, }: {
77
- deps: [...(D | unknown[])];
78
- options?: UseInjectSharedOptions;
79
- }): ProviderModuleGetManySignature<D>;
80
-
81
- /**
82
- * Can be used to retrieve many resolved `dependencies` from the module container at once.
83
- *
84
- * **Note:** _By using this hook, the dependencies will be injected on each re-render process._
85
- * _If you need to inject the dependencies only once, you must use the `useInjectMany` hook._
86
- *
87
- * @param options See {@link UseInjectSharedOptions}.
88
- * @param deps Either one or more {@link ProviderToken}.
89
- * @returns Tuple containing the {@link D | dependencies}.
90
- */
91
- declare function useInjectManyOnRender<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>({ deps, }: {
92
- deps: [...(D | unknown[])];
93
- options?: UseInjectSharedOptions;
94
- }): ProviderModuleGetManySignature<D>;
95
-
96
- declare function useExposeComponentModuleContext(): void;
97
-
98
- /**
99
- * This is an **experimental** hook which can be used to make sure that a component will re-render when a children
100
- * exposes its internal context module.
101
- *
102
- * It works best with the `useInjectOnRender` hook, as it'll re-resolve all the required dependencies
103
- * of the injected ProviderToken.
104
- *
105
- * **Use it carefully as it may lead to unnecessary re-render cycles or it may even not work as expected!**
106
- * **It's safer to use the `TapIntoComponent` wrapper component with the `contextInstance` to manually inject the**
107
- * **contextualized dependencies of the children into a parent component service!**
108
- *
109
- * @experimental
110
- */
111
- declare function useRerenderOnChildrenModuleContextLoaded(): void;
112
-
113
- /**
114
- * The `React.Context` value to be provided to a `React.Provider`.
115
- *
116
- * Its default value is a reference to the {@link AppModule}.
117
- */
118
- declare const REACT_X_INJECTION_CONTEXT: react.Context<{
119
- ctx: IComponentProviderModule;
120
- }>;
121
- declare const REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT: react.Context<Map<string, IComponentProviderModule>>;
122
- declare const REACT_X_INJECTION_EXPOSED_COMPONENT_RERENDER_ON_CTX_CHANGE: react.Context<{
123
- r: number;
124
- }>;
125
-
126
- interface ModuleProviderProps {
127
- children?: React.ReactNode;
128
- render?: () => React.ReactNode;
129
- /** The {@link IComponentProviderModule | ComponentProviderModule} instance which must be accessible by this component. */
130
- module: IComponentProviderModule;
131
- /**
132
- * Provide an object containing the initialization {@link ProviderModuleConstructor | options} so the {@link ModuleProviderProps.module | module}
133
- * can be re-initialized when the component re-mounts _**(It'll happen only if it has been previously disposed!)**_.
134
- *
135
- * **Note:** _This is an advanced option and should be used only if you fully understand how the {@link ModuleProviderProps.module | module}_
136
- * _initialization process works!_
137
- * _For more details refer to the {@link https://adimarianmutu.github.io/x-injection/index.html | xInjection} offical docs._
138
- */
139
- tryReInitModuleOnMount?: ProviderModuleOptions;
140
- /**
141
- * When set to `true` it'll automatically dispose
142
- * the provided {@link ModuleProviderProps.module | module} during the
143
- * component `unmount` process.
144
- *
145
- * **Note:** _This is an advanced option and should be used only if you fully understand how the {@link ModuleProviderProps.module | module}_
146
- * _dispose process works!_
147
- * _For more details refer to the {@link https://adimarianmutu.github.io/x-injection/index.html | xInjection} offical docs._
148
- *
149
- * Defaults to `false`.
150
- */
151
- disposeModuleOnUnmount?: boolean;
152
- }
70
+ declare function useInjectMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>(...deps: D | unknown[]): ProviderModuleGetManySignature<D>;
153
71
 
154
- declare function ModuleProvider({ children, render, module, tryReInitModuleOnMount, disposeModuleOnUnmount, }: ModuleProviderProps): react_jsx_runtime.JSX.Element;
72
+ /** Can be used to retrieve the {@link IComponentProviderModule} from the current context. */
73
+ declare function useComponentModule(): IComponentProviderModule;
155
74
 
156
75
  /** A superset of the {@link ProviderModule} used to integrate within a `React` component. */
157
76
  declare class ComponentProviderModule extends ProviderModule implements IComponentProviderModule {
158
77
  protected readonly _initializedFromComponent: IComponentProviderModuleNaked['_initializedFromComponent'];
159
- protected readonly _initialOptions: IComponentProviderModuleNaked['_initialOptions'];
160
78
  constructor(options: ProviderModuleOptions);
161
79
  toNaked(): IComponentProviderModuleNaked & IProviderModuleNaked;
80
+ clone(options?: CloneParams): IComponentProviderModule;
162
81
  dispose(): void;
163
82
  /**
164
83
  * **Publicly visible when the instance is casted to {@link IComponentProviderModuleNaked}.**
165
84
  *
166
- * See {@link IComponentProviderModuleNaked._convertToContextualizedComponentInstance}.
85
+ * See {@link IComponentProviderModuleNaked._createContextualizedComponentInstance}.
167
86
  */
168
- protected _convertToContextualizedComponentInstance(): IComponentProviderModule;
87
+ protected _createContextualizedComponentInstance(): IComponentProviderModule;
169
88
  }
170
89
 
171
- interface TapIntoComponentContextProps {
172
- children: React.ReactNode;
173
- /**
174
- * A callback can be provided to fully get access to the `ProviderModule` of the component instance,
175
- * as long as the component is exposing it by using the `useExposeComponentModuleContext` hook.
176
- *
177
- * @param ctx A context map of modules.
178
- *
179
- * @example
180
- * ```tsx
181
- * function UserComponent(props: UserComponentProps) {
182
- * // This is required in order to correctly expose the ctx!
183
- * useExposeComponentModuleContext();
184
- *
185
- * const [userProfileSettings, userSecuritySettings] = useInjectMany({ deps: [UserProfileSettings, UserSecuritySettings] });
186
- *
187
- * return null;
188
- * }
189
- *
190
- * function UserPage(props: UserPageProps) {
191
- * return (
192
- * <TapIntoComponent
193
- * contextInstance={(ctx)) => ({
194
- * tryGet: UserComponentModule,
195
- * thenDo: (ctx) => {
196
- * const services = ctx.getMany(...);
197
- * }
198
- * })}>
199
- * <UserComponent {...props.userComponentProps} />
200
- * </TapIntoComponent>
201
- * );
202
- * }
203
- * ```
204
- *
205
- * **Or without the fluid syntax:**
206
- *
207
- * ```tsx
208
- * function UserPage(props: UserPageProps) {
209
- * return (
210
- * <TapIntoComponent
211
- * contextInstance={(ctxMap)) => {
212
- * const ctx = ctxMap.get(UserComponentModule.toString());
213
- * if (!ctx) return;
214
- *
215
- * const services = ctx.getMany(...);
216
- * }}>
217
- * <UserComponent {...props.userComponentProps} />
218
- * </TapIntoComponent>
219
- * );
220
- * }
221
- * ````
222
- */
223
- contextInstance?: (ctx: Map<string, IComponentProviderModule>) => void | WithComponentInstanceCtxFluidSyntax;
224
- }
225
- interface WithComponentInstanceCtxFluidSyntax {
226
- /** The {@link IComponentProviderModule | module} to look for in the `context map`. */
227
- tryGet: IComponentProviderModule;
228
- /**
229
- * Provide a callback which will be invoked when the `context map` has
230
- * the {@link tryGet | module} requested.
231
- *
232
- * @param module The contextualized instance of the {@link IComponentProviderModule} extracted from the children.
233
- */
234
- thenDo: (module: IComponentProviderModule) => void | Promise<void>;
235
- }
90
+ /**
91
+ * Can be used to easily provide a {@link module} to any component.
92
+ *
93
+ * @example
94
+ * ```tsx
95
+ * interface MyComponentProps {
96
+ * firstName: string;
97
+ * lastName: string;
98
+ * }
99
+ *
100
+ * export const MyComponent = provideModuleToComponent(
101
+ * MyComponentModule,
102
+ * ({ firstName, lastName }: MyComponentProps) => {
103
+ * const service = useInject(MyComponentService);
104
+ *
105
+ * return <h1>Hello {service.computeUserName(firstName, lastName)}!</h1>
106
+ * }
107
+ * );
108
+ *
109
+ * function App() {
110
+ * return <MyComponent firstName={'John'} lastName={'Doe'} />;
111
+ * }
112
+ * ```
113
+ *
114
+ * @param module The {@link IComponentProviderModule | Module} which should be consumed by the {@link component}.
115
+ * @returns The provided {@link toComponent | Component}.
116
+ */
117
+ declare function provideModuleToComponent<P extends Record<string, any>, C extends ReactElementWithProviderModule<P> = ReactElementWithProviderModule<P>>(module: IComponentProviderModule, component: ReactElementWithProviderModule<P>): C;
118
+ type ReactElementWithProviderModule<P extends Record<string, any>> = (p: PropsWithModule<P>) => React.ReactNode;
236
119
 
237
120
  /**
238
- * This component is the standard way to "tap into" an instance of the component
239
- * in order to get access to its scoped module container and its _(exposed)_ dependencies _instances_.
121
+ * Can be used to easily provide a {@link module} to any component.
240
122
  *
241
- * @param contextInstance See {@link TapIntoComponentContextProps.contextInstance}.
242
- * @param exposed See {@link TapIntoComponentContextProps.exposed}.
123
+ * @example
124
+ * ```tsx
125
+ * interface MyComponentProps {
126
+ * firstName: string;
127
+ * lastName: string;
128
+ * }
129
+ *
130
+ * function MyComponent({ firstName, lastName }: MyComponentProps) {
131
+ * const service = useInject(MyComponentService);
132
+ *
133
+ * return <h1>Hello {service.computeUserName(firstName, lastName)}!</h1>
134
+ * }
135
+ *
136
+ * function App() {
137
+ * return (
138
+ * <ProvideModule module={MyComponentModule}>
139
+ * <MyComponent firstName={'John'} lastName={'Doe'} />
140
+ * </ProvideModule>
141
+ * );
142
+ * }
143
+ * ```
144
+ *
145
+ * @param param0 See {@link ProvideModuleFunctionParams}.
146
+ * @returns The provided {@link toComponent | Component}.
243
147
  */
244
- declare function TapIntoComponent({ children, contextInstance }: TapIntoComponentContextProps): react_jsx_runtime.JSX.Element;
148
+ declare function ProvideModule({ module, children }: ProvideModuleFunctionParams): react_jsx_runtime.JSX.Element;
149
+ interface ProvideModuleFunctionParams {
150
+ /** The {@link IComponentProviderModule | Module} which should be consumed by the {@link children | component}. */
151
+ module: IComponentProviderModule;
152
+ children: react__default.ReactElement;
153
+ }
154
+
155
+ declare function hookFactory<P extends HookParams, D extends any[], T>({ use: hook, inject, }: HookFactoryParams<P, D, T>): (p: P) => T;
156
+ interface HookFactoryParams<P extends HookParams, D extends any[], T> {
157
+ use: HookWithProviderModuleDependencies<P, D, T>;
158
+ inject: ProviderToken[];
159
+ }
160
+ type HookWithProviderModuleDependencies<P extends HookParams, D extends any[], T> = (p: HookWithDeps<P, D>) => T;
161
+ type HookWithDeps<P extends HookParams, D extends any[]> = P & {
162
+ /** Array containing the resolved dependencies from the component context. */
163
+ deps: D;
164
+ };
165
+ type HookParams = Record<string, any> | void;
245
166
 
246
- export { ComponentProviderModule, type IComponentProviderModule, type IComponentProviderModuleNaked, ModuleProvider, REACT_X_INJECTION_CONTEXT, REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT, REACT_X_INJECTION_EXPOSED_COMPONENT_RERENDER_ON_CTX_CHANGE, TapIntoComponent, type TapIntoComponentContextProps, type UseInjectOptions, type UseInjectSharedOptions, type WithComponentInstanceCtxFluidSyntax, useExposeComponentModuleContext, useInject, useInjectMany, useInjectManyOnRender, useInjectOnRender, useRerenderOnChildrenModuleContextLoaded };
167
+ export { ComponentProviderModule, type HookFactoryParams, type HookWithDeps, type HookWithProviderModuleDependencies, type IComponentProviderModule, type IComponentProviderModuleNaked, type PropsWithModule, ProvideModule, type ProvideModuleFunctionParams, REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT, type ReactElementWithProviderModule, type UseInjectOptions, hookFactory, provideModuleToComponent, useComponentModule, useInject, useInjectMany };
package/dist/index.js CHANGED
@@ -1,186 +1,160 @@
1
- var e = Object.defineProperty, t = (t, n) => e(t, "name", {
2
- value: n,
1
+ var e = Object.defineProperty, t = (t, o) => e(t, "name", {
2
+ value: o,
3
3
  configurable: !0
4
4
  });
5
5
 
6
- import { useRef as n } from "react";
6
+ import { AppModule as o } from "@adimm/x-injection";
7
7
 
8
- function o(e) {
9
- const t = n(null);
10
- return null === t.current && (t.current = {
11
- value: e()
12
- }), t.current?.value;
13
- }
8
+ import { createContext as n } from "react";
14
9
 
15
- t(o, "useOnce");
10
+ var r = n(o);
16
11
 
17
- import { useEffect as r, useRef as i, useState as s } from "react";
12
+ import { useContext as i } from "react";
18
13
 
19
- function c(e) {
20
- const t = i(void 0), n = i(!1), o = i(!1), [, c] = s(0);
21
- n.current && (o.current = !0), r((() => (n.current || (t.current = e(), n.current = !0),
22
- c((e => e + 1)), () => {
23
- o.current && t.current?.();
24
- })), []);
14
+ function s() {
15
+ return i(r);
25
16
  }
26
17
 
27
- t(c, "useEffectOnce");
28
-
29
- import { useContext as u } from "react";
18
+ function c(e, t) {
19
+ return s().get(e, t?.isOptional);
20
+ }
30
21
 
31
- import { AppModule as a } from "@adimm/x-injection";
22
+ function a(...e) {
23
+ return s().getMany(...e);
24
+ }
32
25
 
33
- import { createContext as d } from "react";
26
+ t(s, "useComponentModule"), t(c, "useInject"), t(a, "useInjectMany");
34
27
 
35
- var l = d(a), p = d(new Map), m = d({
36
- r: 0
37
- });
28
+ import { InjectionScope as m, ProviderModule as p, ProviderModuleHelpers as d } from "@adimm/x-injection";
38
29
 
39
- import { useCallback as f, useContext as x } from "react";
30
+ var u = class e extends p {
31
+ static {
32
+ t(this, "ComponentProviderModule");
33
+ }
34
+ _initializedFromComponent;
35
+ constructor(e) {
36
+ super(d.buildInternalConstructorParams({
37
+ ...e,
38
+ defaultScope: e.defaultScope ?? m.Singleton,
39
+ identifier: Symbol(`Component${e.identifier.description}`)
40
+ })), this._initializedFromComponent = !1;
41
+ }
42
+ toNaked() {
43
+ return this;
44
+ }
45
+ clone(t) {
46
+ let o = [ ...this.providers ];
47
+ t?.providersMap && (o = o.map((e => t.providersMap(e, this))));
48
+ const n = new e(d.buildInternalConstructorParams({
49
+ isAppModule: this.isAppModule,
50
+ identifier: Symbol(this.identifier.description.replace("Component", "")),
51
+ defaultScope: this.defaultScope.native,
52
+ dynamicExports: this.dynamicExports,
53
+ onReady: this.onReady,
54
+ onDispose: this.onDispose,
55
+ importedProvidersMap: t?.importedProvidersMap,
56
+ imports: [ ...this.imports ],
57
+ providers: o,
58
+ exports: [ ...this.exports ]
59
+ }));
60
+ return n._initializedFromComponent = this._initializedFromComponent, n;
61
+ }
62
+ dispose() {
63
+ this._dispose();
64
+ }
65
+ _createContextualizedComponentInstance() {
66
+ if (this._initializedFromComponent) return this;
67
+ const e = this.clone().toNaked();
68
+ return e.identifier = Symbol(`Contextualized${e.identifier.description}`), e._initializedFromComponent = !0,
69
+ e;
70
+ }
71
+ };
40
72
 
41
- function C({children: e, render: t, module: n, tryReInitModuleOnMount: o, disposeModuleOnUnmount: r}) {
42
- const i = n.toNaked().isAppModule, s = f((() => t?.()), []), c = {
43
- ctx: i ? n : n.toNaked()._convertToContextualizedComponentInstance()
44
- };
45
- return React.createElement(l.Provider, {
46
- value: c
47
- }, React.createElement(m.Provider, {
48
- value: {
49
- r: 0
50
- }
51
- }, React.createElement(v, {
52
- children: e ?? React.createElement(s, null),
53
- module: c,
54
- tryReInitModuleOnMount: o,
55
- disposeModuleOnUnmount: r
56
- })));
57
- }
73
+ import { useMemo as l } from "react";
58
74
 
59
- function v({children: e, module: t, tryReInitModuleOnMount: n, disposeModuleOnUnmount: o = !1}) {
60
- const r = x(p), i = x(m);
61
- return c((() => {
62
- const e = t.ctx.toNaked();
63
- if (r) {
64
- const e = t.ctx.toNaked().imports.map((e => r.get(e.toString())?.toString() === e.toString() ? r.get(e.toString()) : e));
65
- e.length > 0 && (t.ctx.toNaked()._lazyInit({
66
- ...t.ctx.toNaked()._initialOptions,
67
- imports: e
68
- }), i.r++);
69
- }
70
- return e.isDisposed && n && e._lazyInit(n), () => {
71
- o && !e.isDisposed && e._dispose();
72
- };
73
- })), e;
74
- }
75
+ import { useEffect as f, useRef as h, useState as v } from "react";
75
76
 
76
- function M(e, t) {
77
- return u(l).ctx.get(e, t?.isOptional);
77
+ function C(e) {
78
+ const t = h(void 0), o = h(!1), n = h(!1), [, r] = v(0);
79
+ o.current && (n.current = !0), f((() => (o.current || (t.current = e(), o.current = !0),
80
+ r((e => e + 1)), () => {
81
+ n.current && t.current?.();
82
+ })), []);
78
83
  }
79
84
 
80
- function h(e, t) {
81
- return o((() => M(e, t)));
85
+ function y(e, t) {
86
+ const o = l((() => (t ?? e).toNaked()._createContextualizedComponentInstance()), [ e, t ]);
87
+ return C((() => () => {
88
+ o.dispose();
89
+ })), o;
82
90
  }
83
91
 
84
- t(C, "ModuleProvider"), t(v, "XInjectionChildrenRenderer"), t(M, "useInjectOnRender"),
85
- t(h, "useInject");
92
+ t(C, "useEffectOnce"), t(y, "useContextualizedModule");
86
93
 
87
- import { useContext as I } from "react";
94
+ import { isFunction as M } from "@adimm/x-injection";
88
95
 
89
- function O({deps: e}) {
90
- return I(l).ctx.getMany(...e);
96
+ function x(e, t, o) {
97
+ const n = {
98
+ ...t
99
+ };
100
+ return ("object" == typeof e && "type" in e && M(e.type) || M(e)) && (n.module = o),
101
+ n;
91
102
  }
92
103
 
93
- function g({deps: e, options: t}) {
94
- return o((() => O({
95
- options: t,
96
- deps: e
97
- })));
104
+ function P(e, t) {
105
+ return o => {
106
+ const n = y(e, o.module);
107
+ return React.createElement(r.Provider, {
108
+ value: n
109
+ }, React.createElement(j, {
110
+ module: n,
111
+ componentProps: o,
112
+ component: t
113
+ }));
114
+ };
98
115
  }
99
116
 
100
- t(O, "useInjectManyOnRender"), t(g, "useInjectMany");
101
-
102
- import { useContext as R } from "react";
103
-
104
- function _() {
105
- const e = R(l);
106
- R(p).set(e.ctx.toString(), e.ctx);
117
+ function j({module: e, component: t, componentProps: o}) {
118
+ return React.createElement(React.Fragment, null, t(x(t, o, e)));
107
119
  }
108
120
 
109
- t(_, "useExposeComponentModuleContext");
121
+ t(x, "forwardPropsWithModule"), t(P, "provideModuleToComponent"), t(j, "ComponentRenderer");
110
122
 
111
- import { useContext as S, useEffect as y, useState as E } from "react";
123
+ import z from "react";
112
124
 
113
- function j() {
114
- const e = S(m), [, t] = E(0);
115
- y((() => {
116
- t((e => e + 1));
117
- }), [ e.r ]);
125
+ function E({module: e, children: t}) {
126
+ const o = t.props ?? {}, n = y(e, o.module);
127
+ return z.createElement(r.Provider, {
128
+ value: n
129
+ }, z.cloneElement(t, x(t, o, n)));
118
130
  }
119
131
 
120
- t(j, "useRerenderOnChildrenModuleContextLoaded");
132
+ t(E, "ProvideModule");
133
+
134
+ import { useMemo as F } from "react";
121
135
 
122
- import { InjectionScope as P, isClass as k, isClassOrFunction as z, ProviderModule as N, ProviderModuleHelpers as b } from "@adimm/x-injection";
136
+ import { XInjectionProviderModuleError as _ } from "@adimm/x-injection";
123
137
 
124
- var D = class e extends N {
138
+ var b = class e extends _ {
125
139
  static {
126
- t(this, "ComponentProviderModule");
127
- }
128
- _initializedFromComponent;
129
- _initialOptions;
130
- constructor(e) {
131
- super(b.buildInternalConstructorParams({
132
- ...e,
133
- defaultScope: e.defaultScope ?? P.Transient,
134
- identifier: Symbol(`Component${e.identifier.description}`)
135
- })), this._initializedFromComponent = !1, this._initialOptions = e;
136
- }
137
- toNaked() {
138
- return this;
139
- }
140
- dispose() {
141
- this._dispose();
142
- }
143
- _convertToContextualizedComponentInstance() {
144
- if (this.isAppModule || this.isDisposed) return this;
145
- const t = this._getProviders().map((e => z(e) ? k(e) ? {
146
- scope: P.Singleton,
147
- provide: e,
148
- useClass: e
149
- } : {
150
- provide: e,
151
- useValue: e
152
- } : {
153
- ...e,
154
- scope: P.Singleton
155
- })), n = new e({
156
- ...this._initialOptions,
157
- providers: t
158
- });
159
- return n._initializedFromComponent = !0, n;
140
+ t(this, "XInjectionHookFactoryError");
160
141
  }
142
+ name=e.name;
161
143
  };
162
144
 
163
- import { useContext as T, useEffect as w, useMemo as F } from "react";
164
-
165
- function U({children: e, contextInstance: t}) {
166
- const n = F((() => new Map), []);
167
- return React.createElement(p.Provider, {
168
- value: n
169
- }, React.createElement(A, {
170
- contextInstance: t
171
- }), e);
172
- }
173
-
174
- function A({contextInstance: e}) {
175
- const t = T(p);
176
- return w((() => {
177
- const n = e?.(t);
178
- if (!n) return;
179
- const o = t.get(n.tryGet.toString());
180
- o && n.thenDo(o);
181
- }), [ t ]), null;
145
+ function g({use: e, inject: t}) {
146
+ return o => {
147
+ const n = s(), r = F((() => {
148
+ if (0 === t.length) throw new b(n, "The 'deps' property array is missing!");
149
+ return n.getMany(...t);
150
+ }), [ t ]);
151
+ return e({
152
+ ...o,
153
+ deps: [ ...r ]
154
+ });
155
+ };
182
156
  }
183
157
 
184
- t(U, "TapIntoComponent"), t(A, "CtxExposer");
158
+ t(g, "hookFactory");
185
159
 
186
- export { D as ComponentProviderModule, C as ModuleProvider, l as REACT_X_INJECTION_CONTEXT, p as REACT_X_INJECTION_EXPOSED_COMPONENT_MODULE_CONTEXT, m as REACT_X_INJECTION_EXPOSED_COMPONENT_RERENDER_ON_CTX_CHANGE, U as TapIntoComponent, _ as useExposeComponentModuleContext, h as useInject, g as useInjectMany, O as useInjectManyOnRender, M as useInjectOnRender, j as useRerenderOnChildrenModuleContextLoaded };//# sourceMappingURL=index.js.map
160
+ export { u as ComponentProviderModule, E as ProvideModule, r as REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT, g as hookFactory, P as provideModuleToComponent, s as useComponentModule, c as useInject, a as useInjectMany };//# sourceMappingURL=index.js.map