@adimm/x-injection-reactjs 0.3.0 → 0.3.1

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/README.md CHANGED
@@ -364,13 +364,7 @@ export interface DropdownProps {
364
364
 
365
365
  export const Dropdown = provideModuleToComponent<DropdownProps>(
366
366
  ListviewModule,
367
- ({
368
- listviewProps,
369
- initialSelectedValue,
370
- // Here it is important that we get access to the contextualized module
371
- // so we can forward it to the `Listview` component!
372
- module,
373
- }) => {
367
+ ({ listviewProps, initialSelectedValue }) => {
374
368
  const service = useInject(DropdownService);
375
369
 
376
370
  /* Remaining fancy implementation */
@@ -379,9 +373,9 @@ export const Dropdown = provideModuleToComponent<DropdownProps>(
379
373
  <div className="fancy-dropdown">
380
374
  <span>{initialSelectedValue}</span>
381
375
 
382
- {/* Here we forward the contextualized module which will be sent from the parent component consuming this component,
383
- in our case, the `Autocomplete` component. */}
384
- <Listview module={module} />
376
+ {/* Here we tell the `ListView` component to actually use the `ListviewService` instance we provide via the `useValue` property. */}
377
+ {/* Each `useInject(ListviewService)` used inside the `ListView` component will automatically resolve to `service.listviewService`. */}
378
+ <Listview {...listviewProps} inject={[{ provide: ListviewService, useValue: service.listviewService }]} />
385
379
  </div>
386
380
  );
387
381
  }
@@ -437,16 +431,11 @@ export interface AutocompleteProps {
437
431
  currentText: string;
438
432
  }
439
433
 
440
- export const Autocomplete = provideModuleToComponent<AutocompleteProps>(
441
- AutocompleteModule,
442
- ({
443
- dropdownProps,
444
- currentText,
445
-
446
- module,
447
- }) => {
434
+ export const Autocomplete = provideModuleToComponent<AutocompleteProps>(AutocompleteModule, ({ inputboxProps, dropdownProps, currentText }) => {
448
435
  const service = useInject(AutocompleteService);
449
436
 
437
+ service.inputboxService.currentValue = currentText;
438
+
450
439
  console.log(service.dropdownService.listviewService.items);
451
440
  // Produces: [29, 9, 1969]
452
441
 
@@ -454,9 +443,9 @@ export const Autocomplete = provideModuleToComponent<AutocompleteProps>(
454
443
 
455
444
  return (
456
445
  <div className="fancy-autocomplete">
457
- {/* Let's not forget to forward the module to both components we want to control */}
458
- <Inputbox {...inputboxProps} module={module} >
459
- <Dropdown {...dropdownProps} module={module} />
446
+ {/* Let's not forget to replace the injection providers of both components we want to control */}
447
+ <Inputbox {...inputboxProps} inject={[{ provide: InputboxService, useValue: service.inputboxService }]} >
448
+ <Dropdown {...dropdownProps} inject={[{ provide: DropdownService, useValue: service.dropdownService }]} />
460
449
  </div>
461
450
  );
462
451
  }
package/dist/index.cjs CHANGED
@@ -1,34 +1,34 @@
1
1
  "use strict";
2
2
 
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", {
3
+ var e, t = Object.create, r = Object.defineProperty, o = Object.getOwnPropertyDescriptor, n = Object.getOwnPropertyNames, i = Object.getPrototypeOf, s = Object.prototype.hasOwnProperty, u = (e, t) => r(e, "name", {
4
4
  value: t,
5
5
  configurable: !0
6
- }), a = (e, t, i, s) => {
7
- if (t && "object" == typeof t || "function" == typeof t) for (let a of n(t)) u.call(e, a) || a === i || o(e, a, {
6
+ }), a = (e, t, i, u) => {
7
+ if (t && "object" == typeof t || "function" == typeof t) for (let a of n(t)) s.call(e, a) || a === i || r(e, a, {
8
8
  get: () => t[a],
9
- enumerable: !(s = r(t, a)) || s.enumerable
9
+ enumerable: !(u = o(t, a)) || u.enumerable
10
10
  });
11
11
  return e;
12
- }, d = (e, r, n) => (n = null != e ? t(i(e)) : {}, a(!r && e && e.__esModule ? n : o(n, "default", {
12
+ }, d = (e, o, n) => (n = null != e ? t(i(e)) : {}, a(!o && e && e.__esModule ? n : r(n, "default", {
13
13
  value: e,
14
14
  enumerable: !0
15
15
  }), e)), c = {};
16
16
 
17
17
  ((e, t) => {
18
- for (var r in t) o(e, r, {
19
- get: t[r],
18
+ for (var o in t) r(e, o, {
19
+ get: t[o],
20
20
  enumerable: !0
21
21
  });
22
22
  })(c, {
23
23
  ComponentProviderModule: () => C,
24
24
  ProvideModule: () => _,
25
25
  REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT: () => p,
26
- hookFactory: () => q,
27
- provideModuleToComponent: () => z,
26
+ hookFactory: () => A,
27
+ provideModuleToComponent: () => S,
28
28
  useComponentModule: () => f,
29
29
  useInject: () => h,
30
30
  useInjectMany: () => M
31
- }), module.exports = (e = c, a(o({}, "__esModule", {
31
+ }), module.exports = (e = c, a(r({}, "__esModule", {
32
32
  value: !0
33
33
  }), e));
34
34
 
@@ -46,40 +46,40 @@ function M(...e) {
46
46
  return f().getMany(...e);
47
47
  }
48
48
 
49
- s(f, "useComponentModule"), s(h, "useInject"), s(M, "useInjectMany");
49
+ u(f, "useComponentModule"), u(h, "useInject"), u(M, "useInjectMany");
50
50
 
51
51
  var v = require("@adimm/x-injection"), C = class e extends v.ProviderModule {
52
52
  static {
53
- s(this, "ComponentProviderModule");
53
+ u(this, "ComponentProviderModule");
54
54
  }
55
55
  originalIdentifier;
56
56
  hasContextualizedImports;
57
57
  initializedFromComponent;
58
58
  constructor(e) {
59
- const t = Symbol(`Component${e.identifier.description}`), o = !e.markAsGlobal && (e.contextualizeImports ?? !0), r = o ? new Map : void 0;
59
+ const t = Symbol(`Component${e.identifier.description}`), r = !e.markAsGlobal && (e.contextualizeImports ?? !0), o = r ? new Map : void 0;
60
60
  super(v.ProviderModuleHelpers.buildInternalConstructorParams({
61
61
  ...e,
62
62
  defaultScope: e.defaultScope ?? v.InjectionScope.Singleton,
63
63
  identifier: t,
64
- imports: o ? e.imports?.map((e => {
64
+ imports: r ? e.imports?.map((e => {
65
65
  const n = "function" == typeof e ? e() : e;
66
- return o ? () => {
66
+ return r ? () => {
67
67
  const e = n._createContextualizedComponentInstance(t);
68
- return r.set(n.originalIdentifier.toString(), e), e;
68
+ return o.set(n.originalIdentifier.toString(), e), e;
69
69
  } : n;
70
70
  })) : e.imports,
71
- dynamicExports: s(((e, t) => o ? t.map((e => {
71
+ dynamicExports: u(((e, t) => r ? t.map((e => {
72
72
  if (!(e instanceof v.ProviderModule)) return e;
73
- return r.get(e.originalIdentifier.toString());
73
+ return o.get(e.originalIdentifier.toString());
74
74
  })) : t), "dynamicExports")
75
- })), this.originalIdentifier = e.identifier, this.hasContextualizedImports = o,
75
+ })), this.originalIdentifier = e.identifier, this.hasContextualizedImports = r,
76
76
  this.initializedFromComponent = !1;
77
77
  }
78
78
  toNaked() {
79
79
  return this;
80
80
  }
81
81
  clone(t) {
82
- const o = t, r = new e(v.ProviderModuleHelpers.buildInternalConstructorParams({
82
+ const r = t, o = new e(v.ProviderModuleHelpers.buildInternalConstructorParams({
83
83
  isAppModule: this.isAppModule,
84
84
  markAsGlobal: this.isMarkedAsGlobal,
85
85
  identifier: Symbol(this.identifier.description.replace("Component", "")),
@@ -92,105 +92,112 @@ var v = require("@adimm/x-injection"), C = class e extends v.ProviderModule {
92
92
  imports: [ ...this.imports ],
93
93
  providers: [ ...this.providers ],
94
94
  exports: [ ...this.exports ],
95
- ...o
95
+ ...r
96
96
  }));
97
- return r.initializedFromComponent = this.initializedFromComponent, r;
98
- }
99
- async dispose() {
100
- await super.dispose();
97
+ return o.initializedFromComponent = this.initializedFromComponent, o.registeredBindingSideEffects = new Map(this.registeredBindingSideEffects),
98
+ o;
101
99
  }
102
100
  _createContextualizedComponentInstance(e) {
103
101
  if (this.initializedFromComponent) return this;
104
102
  const t = this.clone().toNaked();
105
- return t.identifier = Symbol(`${e ? `[Parent:${e.description ?? "Unknown"}]` : ""}Contextualized${t.identifier.description}`),
103
+ return t.identifier = Symbol(`${e ? `[Importer:${e.description ?? "Unknown"}]` : ""}Contextualized${t.identifier.description}`),
106
104
  t.initializedFromComponent = !0, t;
107
105
  }
108
- }, y = d(require("react"), 1), P = require("react"), x = require("react");
109
-
110
- function I(e) {
111
- const t = (0, x.useRef)(void 0), o = (0, x.useRef)(!1), r = (0, x.useRef)(!1), [, n] = (0,
112
- x.useState)(0);
113
- o.current && (r.current = !0), (0, x.useEffect)((() => (o.current || (t.current = e(),
114
- o.current = !0), n((e => e + 1)), () => {
115
- r.current && t.current?.();
106
+ }, y = d(require("react"), 1), g = require("@adimm/x-injection"), P = require("react"), b = require("react");
107
+
108
+ function x(e) {
109
+ const t = (0, b.useRef)(void 0), r = (0, b.useRef)(!1), o = (0, b.useRef)(!1), [, n] = (0,
110
+ b.useState)(0);
111
+ r.current && (o.current = !0), (0, b.useEffect)((() => (r.current || (t.current = e(),
112
+ r.current = !0), n((e => e + 1)), () => {
113
+ o.current && t.current?.();
116
114
  })), []);
117
115
  }
118
116
 
119
- function b(e, t) {
120
- const o = (0, P.useMemo)((() => {
121
- const o = (t ?? e).toNaked();
122
- return o.isMarkedAsGlobal ? o : o._createContextualizedComponentInstance();
123
- }), [ e, t ]);
124
- return I((() => () => {
125
- o.dispose();
126
- })), o;
117
+ function I(e, t) {
118
+ const r = (0, P.useMemo)((() => {
119
+ const {module: r, inject: o} = t ?? {};
120
+ let n = (r ?? e).toNaked();
121
+ if (n.isMarkedAsGlobal && o) throw new g.InjectionProviderModuleError(n, "The 'inject' prop can be used only with modules which are not marked as global!");
122
+ if (n.isMarkedAsGlobal || (n = n._createContextualizedComponentInstance().toNaked()),
123
+ o) {
124
+ const e = new Map(n.registeredSideEffects);
125
+ n.registeredSideEffects.clear(), o.forEach((e => {
126
+ n.__unbind(e), n.moduleUtils.bindToContainer(e, n.defaultScope.native);
127
+ })), n.registeredBindingSideEffects = e;
128
+ }
129
+ return n;
130
+ }), [ e, t?.inject ]);
131
+ return x((() => () => {
132
+ r.dispose();
133
+ })), r;
127
134
  }
128
135
 
129
- s(I, "useEffectOnce"), s(b, "useContextualizedModule");
136
+ u(x, "useEffectOnce"), u(I, "useContextualizedModule");
130
137
 
131
- var g, j = require("@adimm/x-injection");
138
+ var j, E = require("@adimm/x-injection");
132
139
 
133
140
  !function(e) {
134
- function t(e, t, o) {
135
- const r = {
141
+ function t(e, t, r) {
142
+ const o = {
136
143
  ...t
137
144
  };
138
- return ("object" == typeof e && "type" in e && (0, j.isFunction)(e.type) || (0,
139
- j.isFunction)(e)) && (r.module = o), r;
145
+ return ("object" == typeof e && "type" in e && (0, E.isFunction)(e.type) || (0,
146
+ E.isFunction)(e)) && (o.module = r), o;
140
147
  }
141
- s(t, "forwardPropsWithModule"), e.forwardPropsWithModule = t;
142
- }(g || (g = {}));
148
+ u(t, "forwardPropsWithModule"), e.forwardPropsWithModule = t;
149
+ }(j || (j = {}));
143
150
 
144
- var E = y.default.memo(O);
151
+ var w = y.default.memo(z);
145
152
 
146
- function z(e, t) {
147
- return o => {
148
- const r = b(e, o.module);
153
+ function S(e, t) {
154
+ return r => {
155
+ const o = I(e, r);
149
156
  return y.default.createElement(p.Provider, {
150
- value: r
151
- }, y.default.createElement(E, {
152
- module: r,
153
- componentProps: o,
157
+ value: o
158
+ }, y.default.createElement(w, {
159
+ module: o,
160
+ componentProps: r,
154
161
  component: t
155
162
  }));
156
163
  };
157
164
  }
158
165
 
159
- function O({module: e, component: t, componentProps: o}) {
160
- return y.default.createElement(y.default.Fragment, null, t(g.forwardPropsWithModule(t, o, e)));
166
+ function z({module: e, component: t, componentProps: r}) {
167
+ return y.default.createElement(y.default.Fragment, null, t(j.forwardPropsWithModule(t, r, e)));
161
168
  }
162
169
 
163
- s(z, "provideModuleToComponent"), s(O, "_ComponentRenderer");
170
+ u(S, "provideModuleToComponent"), u(z, "_ComponentRenderer");
164
171
 
165
- var w = d(require("react"), 1);
172
+ var O = d(require("react"), 1);
166
173
 
167
174
  function _({module: e, children: t}) {
168
- const o = t.props ?? {}, r = b(e, o.module), n = (0, w.useMemo)((() => w.default.cloneElement(t, g.forwardPropsWithModule(t, o, r))), [ o, r ]);
169
- return w.default.createElement(p.Provider, {
170
- value: r
175
+ const r = t.props ?? {}, o = I(e, r), n = (0, O.useMemo)((() => O.default.cloneElement(t, j.forwardPropsWithModule(t, r, o))), [ r, o ]);
176
+ return O.default.createElement(p.Provider, {
177
+ value: o
171
178
  }, n);
172
179
  }
173
180
 
174
- s(_, "ProvideModule");
181
+ u(_, "ProvideModule");
175
182
 
176
- var F = require("react"), S = require("@adimm/x-injection"), k = class e extends S.InjectionProviderModuleError {
183
+ var k = require("react"), q = require("@adimm/x-injection"), F = class e extends q.InjectionProviderModuleError {
177
184
  static {
178
- s(this, "InjectionHookFactoryError");
185
+ u(this, "InjectionHookFactoryError");
179
186
  }
180
187
  name=e.name;
181
188
  };
182
189
 
183
- function q({use: e, inject: t}) {
184
- return o => {
185
- const r = f(), n = (0, F.useMemo)((() => {
186
- if (0 === t.length) throw new k(r, "The 'deps' property array is missing!");
187
- return r.getMany(...t);
190
+ function A({use: e, inject: t}) {
191
+ return r => {
192
+ const o = f(), n = (0, k.useMemo)((() => {
193
+ if (0 === t.length) throw new F(o, "The 'deps' property array is missing!");
194
+ return o.getMany(...t);
188
195
  }), [ t ]);
189
196
  return e({
190
- ...o,
197
+ ...r,
191
198
  deps: [ ...n ]
192
199
  });
193
200
  };
194
201
  }
195
202
 
196
- s(q, "hookFactory");//# sourceMappingURL=index.cjs.map
203
+ u(A, "hookFactory");//# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
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/core/provide-module/provide-module.arrow-function.tsx","../src/helpers/hooks/use-contextualized-module.ts","../src/helpers/hooks/use-effect-once.ts","../src/helpers/component-provider-module.ts","../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 IProviderModule,\n type IProviderModuleNaked,\n type ProviderModuleOptionsInternal,\n} from '@adimm/x-injection';\n\nimport type { ComponentProviderModuleOptions, 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 originalIdentifier: symbol;\n protected readonly hasContextualizedImports: IComponentProviderModuleNaked['hasContextualizedImports'];\n protected readonly initializedFromComponent: IComponentProviderModuleNaked['initializedFromComponent'];\n\n constructor(options: ComponentProviderModuleOptions) {\n const identifier = Symbol(`Component${options.identifier.description}`);\n const contextualizeImports = options.markAsGlobal ? false : options.contextualizeImports ?? true;\n const contextualizedImportsCache: Map<string, IProviderModule> | undefined = contextualizeImports\n ? new Map()\n : undefined;\n\n super(\n ProviderModuleHelpers.buildInternalConstructorParams({\n ...options,\n defaultScope: options.defaultScope ?? InjectionScope.Singleton,\n identifier: identifier,\n imports: !contextualizeImports\n ? options.imports\n : options.imports?.map((imp) => {\n const module = (typeof imp === 'function' ? imp() : imp) as IComponentProviderModuleNaked;\n /* istanbul ignore next */\n if (!contextualizeImports) return module;\n\n return () => {\n const ctxModule = module._createContextualizedComponentInstance(identifier);\n\n contextualizedImportsCache!.set(module.originalIdentifier.toString(), ctxModule);\n\n return ctxModule;\n };\n }),\n dynamicExports: (_, exports) => {\n if (!contextualizeImports) return exports;\n\n return exports.map((exp) => {\n if (!(exp instanceof ProviderModule)) return exp;\n\n const cachedCtxModule = contextualizedImportsCache!.get(\n (exp as unknown as IComponentProviderModuleNaked).originalIdentifier.toString()\n )!;\n\n return cachedCtxModule;\n });\n },\n })\n );\n\n this.originalIdentifier = options.identifier;\n this.hasContextualizedImports = contextualizeImports;\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?: Partial<ComponentProviderModuleOptions>): IComponentProviderModule {\n const _options = options as ProviderModuleOptionsInternal;\n\n const clonedModule = new ComponentProviderModule(\n ProviderModuleHelpers.buildInternalConstructorParams({\n isAppModule: this.isAppModule,\n markAsGlobal: this.isMarkedAsGlobal,\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 contextualizeImports: this.hasContextualizedImports,\n importedProvidersMap: this.importedProvidersMap,\n imports: [...this.imports],\n providers: [...this.providers],\n exports: [...this.exports],\n ..._options,\n } as ComponentProviderModuleOptions)\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 override async dispose(): Promise<void> {\n await super.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(parentIdentifier?: symbol): IComponentProviderModule {\n if (this.initializedFromComponent) return this;\n\n const ctxModule = this.clone().toNaked();\n\n /* istanbul ignore next */\n //@ts-expect-error Read-only property\n ctxModule.identifier = Symbol(\n `${parentIdentifier ? `[Parent:${parentIdentifier.description ?? 'Unknown'}]` : ''}Contextualized${ctxModule.identifier.description}`\n );\n ctxModule.initializedFromComponent = true;\n\n return ctxModule;\n }\n\n //#endregion\n}\n","import React from 'react';\n\nimport { ComponentProviderModuleHelpers, useContextualizedModule } from '../../helpers';\nimport type { IComponentProviderModule, PropsWithModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\nconst ComponentRenderer = React.memo(_ComponentRenderer);\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<MyComponentProps>(\n * MyComponentModule,\n * ({ firstName, lastName }) => {\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 as any} />\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(ComponentProviderModuleHelpers.forwardPropsWithModule(component, componentProps, module))}</>;\n}\n\nexport type ReactElementWithProviderModule<P extends Record<string, any>> = (p: PropsWithModule<P>) => React.ReactNode;\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 const module = (forwardedModule ?? originalModule).toNaked();\n\n if (module.isMarkedAsGlobal) return module;\n\n return module._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 namespace ComponentProviderModuleHelpers {\n export 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}\n","import React, { useMemo } from 'react';\n\nimport { ComponentProviderModuleHelpers, 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 const component = useMemo(\n () =>\n React.cloneElement(\n children,\n ComponentProviderModuleHelpers.forwardPropsWithModule(children, componentProps, moduleCtx)\n ),\n [componentProps, moduleCtx]\n );\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n {component}\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 { InjectionHookFactoryError } 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 InjectionHookFactoryError(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 { InjectionProviderModuleError } from '@adimm/x-injection';\n\nexport class InjectionHookFactoryError extends InjectionProviderModuleError {\n override name = InjectionHookFactoryError.name;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;ACAA,yB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G;AACvB,cAAM,IAAIC,0BAA0BL,iBAAiB,uCAAuC;MAC9F;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","originalIdentifier","hasContextualizedImports","initializedFromComponent","constructor","options","identifier","Symbol","description","contextualizeImports","markAsGlobal","contextualizedImportsCache","Map","undefined","ProviderModuleHelpers","buildInternalConstructorParams","defaultScope","InjectionScope","Singleton","imports","map","imp","module","ctxModule","_createContextualizedComponentInstance","set","toString","dynamicExports","_","exports","exp","cachedCtxModule","get","toNaked","clone","_options","clonedModule","isAppModule","isMarkedAsGlobal","replace","native","onReady","onDispose","importedProvidersMap","providers","dispose","parentIdentifier","import_react","import_react","import_react","useEffectOnce","effect","destroyFunc","useRef","undefined","effectCalled","renderAfterCalled","forceRerender","useState","current","useEffect","x","useContextualizedModule","originalModule","forwardedModule","ctxModule","useMemo","module","toNaked","isMarkedAsGlobal","_createContextualizedComponentInstance","useEffectOnce","dispose","import_x_injection","ComponentProviderModuleHelpers","forwardPropsWithModule","component","props","module","isReactElement","result","isFunction","type","ComponentRenderer","React","memo","_ComponentRenderer","provideModuleToComponent","module","component","componentProps","moduleCtx","useContextualizedModule","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","ComponentProviderModuleHelpers","forwardPropsWithModule","import_react","ProvideModule","module","children","componentProps","props","moduleCtx","useContextualizedModule","component","useMemo","React","cloneElement","ComponentProviderModuleHelpers","forwardPropsWithModule","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","import_react","import_x_injection","InjectionHookFactoryError","InjectionProviderModuleError","name","hookFactory","use","hook","inject","p","componentModule","useComponentModule","deps","useMemo","length","InjectionHookFactoryError","getMany"]}
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/core/provide-module/provide-module.arrow-function.tsx","../src/helpers/hooks/use-contextualized-module.ts","../src/helpers/hooks/use-effect-once.ts","../src/helpers/component-provider-module.ts","../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 IProviderModule,\n type IProviderModuleNaked,\n type ProviderModuleOptionsInternal,\n} from '@adimm/x-injection';\n\nimport type { ComponentProviderModuleOptions, 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 originalIdentifier: symbol;\n protected readonly hasContextualizedImports: IComponentProviderModuleNaked['hasContextualizedImports'];\n protected readonly initializedFromComponent: IComponentProviderModuleNaked['initializedFromComponent'];\n\n constructor(options: ComponentProviderModuleOptions) {\n const identifier = Symbol(`Component${options.identifier.description}`);\n const contextualizeImports = options.markAsGlobal ? false : options.contextualizeImports ?? true;\n const contextualizedImportsCache: Map<string, IProviderModule> | undefined = contextualizeImports\n ? new Map()\n : undefined;\n\n super(\n ProviderModuleHelpers.buildInternalConstructorParams({\n ...options,\n defaultScope: options.defaultScope ?? InjectionScope.Singleton,\n identifier: identifier,\n imports: !contextualizeImports\n ? options.imports\n : options.imports?.map((imp) => {\n const module = (typeof imp === 'function' ? imp() : imp) as IComponentProviderModuleNaked;\n /* istanbul ignore next */\n if (!contextualizeImports) return module;\n\n return () => {\n const ctxModule = module._createContextualizedComponentInstance(identifier);\n\n contextualizedImportsCache!.set(module.originalIdentifier.toString(), ctxModule);\n\n return ctxModule;\n };\n }),\n dynamicExports: (_, exports) => {\n if (!contextualizeImports) return exports;\n\n return exports.map((exp) => {\n if (!(exp instanceof ProviderModule)) return exp;\n\n const cachedCtxModule = contextualizedImportsCache!.get(\n (exp as unknown as IComponentProviderModuleNaked).originalIdentifier.toString()\n )!;\n\n return cachedCtxModule;\n });\n },\n })\n );\n\n this.originalIdentifier = options.identifier;\n this.hasContextualizedImports = contextualizeImports;\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?: Partial<ComponentProviderModuleOptions>): IComponentProviderModule {\n const _options = options as ProviderModuleOptionsInternal;\n\n const clonedModule = new ComponentProviderModule(\n ProviderModuleHelpers.buildInternalConstructorParams({\n isAppModule: this.isAppModule,\n markAsGlobal: this.isMarkedAsGlobal,\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 contextualizeImports: this.hasContextualizedImports,\n importedProvidersMap: this.importedProvidersMap,\n imports: [...this.imports],\n providers: [...this.providers],\n exports: [...this.exports],\n ..._options,\n } as ComponentProviderModuleOptions)\n );\n\n //@ts-expect-error Read-only method.\n clonedModule.initializedFromComponent = this.initializedFromComponent;\n //@ts-expect-error Read-only method.\n clonedModule.registeredBindingSideEffects = new Map(this.registeredBindingSideEffects);\n\n return clonedModule;\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(parentIdentifier?: symbol): IComponentProviderModule {\n if (this.initializedFromComponent) return this;\n\n const ctxModule = this.clone().toNaked();\n\n /* istanbul ignore next */\n //@ts-expect-error Read-only property\n ctxModule.identifier = Symbol(\n `${parentIdentifier ? `[Importer:${parentIdentifier.description ?? 'Unknown'}]` : ''}Contextualized${ctxModule.identifier.description}`\n );\n ctxModule.initializedFromComponent = true;\n\n return ctxModule;\n }\n\n //#endregion\n}\n","import React from 'react';\n\nimport { ComponentProviderModuleHelpers, useContextualizedModule } from '../../helpers';\nimport type { IComponentProviderModule, PropsWithModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\nconst ComponentRenderer = React.memo(_ComponentRenderer);\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<MyComponentProps>(\n * MyComponentModule,\n * ({ firstName, lastName }) => {\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);\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n <ComponentRenderer module={moduleCtx} componentProps={componentProps} component={component as any} />\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(ComponentProviderModuleHelpers.forwardPropsWithModule(component, componentProps, module))}</>;\n}\n\nexport type ReactElementWithProviderModule<P extends Record<string, any>> = (p: PropsWithModule<P>) => React.ReactNode;\n","import { InjectionProviderModuleError } from '@adimm/x-injection';\nimport { useMemo } from 'react';\n\nimport type { IComponentProviderModule, PropsWithModule } from '../../types';\nimport { useEffectOnce } from './use-effect-once';\n\nexport function useContextualizedModule(\n originalModule: IComponentProviderModule,\n componentProps?: PropsWithModule<object>\n): IComponentProviderModule {\n const ctxModule = useMemo(() => {\n /* istanbul ignore next */\n const { module: forwardedModule, inject } = componentProps ?? {};\n let module = (forwardedModule ?? originalModule).toNaked();\n\n if (module.isMarkedAsGlobal && inject) {\n throw new InjectionProviderModuleError(\n module,\n `The 'inject' prop can be used only with modules which are not marked as global!`\n );\n }\n\n if (!module.isMarkedAsGlobal) {\n module = module._createContextualizedComponentInstance().toNaked();\n }\n\n if (inject) {\n const sideEffectsOriginal = new Map(module.registeredSideEffects);\n module.registeredSideEffects.clear();\n\n inject.forEach((provider) => {\n module.__unbind(provider);\n\n module.moduleUtils.bindToContainer(provider, module.defaultScope.native);\n });\n\n //@ts-expect-error Read-only property.\n module.registeredBindingSideEffects = sideEffectsOriginal;\n }\n\n return module;\n }, [originalModule, componentProps?.inject]);\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 namespace ComponentProviderModuleHelpers {\n export 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}\n","import React, { useMemo } from 'react';\n\nimport { ComponentProviderModuleHelpers, 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 * 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 PropsWithModule<object>;\n const moduleCtx = useContextualizedModule(module, componentProps);\n const component = useMemo(\n () =>\n React.cloneElement(\n children,\n ComponentProviderModuleHelpers.forwardPropsWithModule(children, componentProps, moduleCtx)\n ),\n [componentProps, moduleCtx]\n );\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n {component}\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 { InjectionHookFactoryError } 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 InjectionHookFactoryError(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 { InjectionProviderModuleError } from '@adimm/x-injection';\n\nexport class InjectionHookFactoryError extends InjectionProviderModuleError {\n override name = InjectionHookFactoryError.name;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;ACAA,yBAA0B;AAC1B,mBAA8B;AAIvB,IAAMA,gDAA4CC,4BAAwCC,4BAAAA;;;ACLjG,IAAAC,gBAA2B;AAMpB,SAASC,qBAAAA;AACd,aAAOC,0BAAWC,yCAAAA;AACpB;AAFgBF;;;ACST,SAASG,UAAaC,UAA4BC,SAA0B;AACjF,QAAMC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,gBAAwB;;;ACDxB,IAAAC,sBAA6C;AAEtC,IAAMC,4BAAN,MAAMA,mCAAkCC,iDAAAA;EAF/C,OAE+CA;;;EACpCC,OAAOF,2BAA0BE;AAC5C;;;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,0BAA0BL,iBAAiB,uCAAuC;MAC9F;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","originalIdentifier","hasContextualizedImports","initializedFromComponent","constructor","options","identifier","Symbol","description","contextualizeImports","markAsGlobal","contextualizedImportsCache","Map","undefined","ProviderModuleHelpers","buildInternalConstructorParams","defaultScope","InjectionScope","Singleton","imports","map","imp","module","ctxModule","_createContextualizedComponentInstance","set","toString","dynamicExports","_","exports","exp","cachedCtxModule","get","toNaked","clone","_options","clonedModule","isAppModule","isMarkedAsGlobal","replace","native","onReady","onDispose","importedProvidersMap","providers","registeredBindingSideEffects","parentIdentifier","import_react","import_x_injection","import_react","import_react","useEffectOnce","effect","destroyFunc","useRef","undefined","effectCalled","renderAfterCalled","forceRerender","useState","current","useEffect","x","useContextualizedModule","originalModule","componentProps","ctxModule","useMemo","module","forwardedModule","inject","toNaked","isMarkedAsGlobal","InjectionProviderModuleError","_createContextualizedComponentInstance","sideEffectsOriginal","Map","registeredSideEffects","clear","forEach","provider","__unbind","moduleUtils","bindToContainer","defaultScope","native","registeredBindingSideEffects","useEffectOnce","dispose","import_x_injection","ComponentProviderModuleHelpers","forwardPropsWithModule","component","props","module","isReactElement","result","isFunction","type","ComponentRenderer","React","memo","_ComponentRenderer","provideModuleToComponent","module","component","componentProps","moduleCtx","useContextualizedModule","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","ComponentProviderModuleHelpers","forwardPropsWithModule","import_react","ProvideModule","module","children","componentProps","props","moduleCtx","useContextualizedModule","component","useMemo","React","cloneElement","ComponentProviderModuleHelpers","forwardPropsWithModule","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","import_react","import_x_injection","InjectionHookFactoryError","InjectionProviderModuleError","name","hookFactory","use","hook","inject","p","componentModule","useComponentModule","deps","useMemo","length","InjectionHookFactoryError","getMany"]}
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import React__default from 'react';
3
- import { ProviderModuleOptions, IProviderModule, IProviderModuleNaked, ProviderToken, ProviderModuleGetManyParam, ProviderModuleGetManySignature, ProviderModule } from '@adimm/x-injection';
3
+ import { ProviderModuleOptions, IProviderModule, IProviderModuleNaked, DependencyProvider, ProviderToken, ProviderModuleGetManyParam, ProviderModuleGetManySignature, ProviderModule } from '@adimm/x-injection';
4
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
5
 
6
6
  interface ComponentProviderModuleOptions extends ProviderModuleOptions {
@@ -58,10 +58,71 @@ type PropsWithModule<P extends Record<string, any>> = P & {
58
58
  /**
59
59
  * The {@link IComponentProviderModule | Module} which this component should consume.
60
60
  *
61
- * **Note:** _You can easily override this in your unit tests to provide a module having mocked providers_
62
- * _without the need to create a new mocked component by using the composable `ProvideModule` method._
61
+ * **Note:** _Can be used to easily mock an entire module._
62
+ *
63
+ * example:
64
+ * ```tsx
65
+ * const CarModule = new ComponentProviderMdule({
66
+ * identifier: Symbol('CarModule'),
67
+ * imports: [CarEngineModule, CarDashboardModule],
68
+ * providers: [CarService],
69
+ * exports: [CarService],
70
+ * });
71
+ *
72
+ * const cbMock = jest.fn();
73
+ *
74
+ * const CarModuleMocked = CarModule.clone({
75
+ * providers: [
76
+ * {
77
+ * provide: CarService, useValue: { startEngine: cbMock }
78
+ * },
79
+ * ]
80
+ * });
81
+ *
82
+ * await act(async () => render(<CarComponent module={CarModuleMocked} />));
83
+ *
84
+ * await waitFor(async () => {
85
+ * expect(cbMock).toHaveBeenCalled();
86
+ * });
87
+ * ```
63
88
  */
64
89
  module?: IComponentProviderModule;
90
+ /**
91
+ * Can be used to control the dependencies consumed by this component.
92
+ * This is useful when you want to provide an already resolved instance of a dependency down the component tree.
93
+ *
94
+ * **Note:** _It'll throw when attempting to provide the `inject` prop to a component using a module_
95
+ * _marked as global!_
96
+ *
97
+ * eg:
98
+ * ```tsx
99
+ * class InputboxService {
100
+ * currentValue = '';
101
+ * }
102
+ *
103
+ * class FormService {
104
+ * constructor(
105
+ * public readonly firstNameInputbox: InputboxService,
106
+ * public readonly lastNameInputbox: InputboxService
107
+ * ) {
108
+ * this.firstNameInputbox.currentValue = 'John';
109
+ * this.lastNameInputbox.currentValue = 'Doe';
110
+ * }
111
+ * }
112
+ *
113
+ * const Form = provideModuleToComponent(FormModule, () => {
114
+ * const service = useInject(FormService);
115
+ *
116
+ * return (
117
+ * <>
118
+ * <Inputbox inject={[{ provide: InputboxService, useValue: service.firstNameInputbox }]} />
119
+ * <Inputbox inject={[{ provide: InputboxService, useValue: service.lastNameInputbox }]} />
120
+ * </>
121
+ * );
122
+ * });
123
+ * ```
124
+ */
125
+ inject?: DependencyProvider[];
65
126
  };
66
127
 
67
128
  declare const REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT: React.Context<IComponentProviderModule>;
@@ -106,7 +167,6 @@ declare class ComponentProviderModule extends ProviderModule implements ICompone
106
167
  constructor(options: ComponentProviderModuleOptions);
107
168
  toNaked(): IComponentProviderModuleNaked & IProviderModuleNaked;
108
169
  clone(options?: Partial<ComponentProviderModuleOptions>): IComponentProviderModule;
109
- dispose(): Promise<void>;
110
170
  /**
111
171
  * **Publicly visible when the instance is casted to {@link IComponentProviderModuleNaked}.**
112
172
  *
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import React__default from 'react';
3
- import { ProviderModuleOptions, IProviderModule, IProviderModuleNaked, ProviderToken, ProviderModuleGetManyParam, ProviderModuleGetManySignature, ProviderModule } from '@adimm/x-injection';
3
+ import { ProviderModuleOptions, IProviderModule, IProviderModuleNaked, DependencyProvider, ProviderToken, ProviderModuleGetManyParam, ProviderModuleGetManySignature, ProviderModule } from '@adimm/x-injection';
4
4
  import * as react_jsx_runtime from 'react/jsx-runtime';
5
5
 
6
6
  interface ComponentProviderModuleOptions extends ProviderModuleOptions {
@@ -58,10 +58,71 @@ type PropsWithModule<P extends Record<string, any>> = P & {
58
58
  /**
59
59
  * The {@link IComponentProviderModule | Module} which this component should consume.
60
60
  *
61
- * **Note:** _You can easily override this in your unit tests to provide a module having mocked providers_
62
- * _without the need to create a new mocked component by using the composable `ProvideModule` method._
61
+ * **Note:** _Can be used to easily mock an entire module._
62
+ *
63
+ * example:
64
+ * ```tsx
65
+ * const CarModule = new ComponentProviderMdule({
66
+ * identifier: Symbol('CarModule'),
67
+ * imports: [CarEngineModule, CarDashboardModule],
68
+ * providers: [CarService],
69
+ * exports: [CarService],
70
+ * });
71
+ *
72
+ * const cbMock = jest.fn();
73
+ *
74
+ * const CarModuleMocked = CarModule.clone({
75
+ * providers: [
76
+ * {
77
+ * provide: CarService, useValue: { startEngine: cbMock }
78
+ * },
79
+ * ]
80
+ * });
81
+ *
82
+ * await act(async () => render(<CarComponent module={CarModuleMocked} />));
83
+ *
84
+ * await waitFor(async () => {
85
+ * expect(cbMock).toHaveBeenCalled();
86
+ * });
87
+ * ```
63
88
  */
64
89
  module?: IComponentProviderModule;
90
+ /**
91
+ * Can be used to control the dependencies consumed by this component.
92
+ * This is useful when you want to provide an already resolved instance of a dependency down the component tree.
93
+ *
94
+ * **Note:** _It'll throw when attempting to provide the `inject` prop to a component using a module_
95
+ * _marked as global!_
96
+ *
97
+ * eg:
98
+ * ```tsx
99
+ * class InputboxService {
100
+ * currentValue = '';
101
+ * }
102
+ *
103
+ * class FormService {
104
+ * constructor(
105
+ * public readonly firstNameInputbox: InputboxService,
106
+ * public readonly lastNameInputbox: InputboxService
107
+ * ) {
108
+ * this.firstNameInputbox.currentValue = 'John';
109
+ * this.lastNameInputbox.currentValue = 'Doe';
110
+ * }
111
+ * }
112
+ *
113
+ * const Form = provideModuleToComponent(FormModule, () => {
114
+ * const service = useInject(FormService);
115
+ *
116
+ * return (
117
+ * <>
118
+ * <Inputbox inject={[{ provide: InputboxService, useValue: service.firstNameInputbox }]} />
119
+ * <Inputbox inject={[{ provide: InputboxService, useValue: service.lastNameInputbox }]} />
120
+ * </>
121
+ * );
122
+ * });
123
+ * ```
124
+ */
125
+ inject?: DependencyProvider[];
65
126
  };
66
127
 
67
128
  declare const REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT: React.Context<IComponentProviderModule>;
@@ -106,7 +167,6 @@ declare class ComponentProviderModule extends ProviderModule implements ICompone
106
167
  constructor(options: ComponentProviderModuleOptions);
107
168
  toNaked(): IComponentProviderModuleNaked & IProviderModuleNaked;
108
169
  clone(options?: Partial<ComponentProviderModuleOptions>): IComponentProviderModule;
109
- dispose(): Promise<void>;
110
170
  /**
111
171
  * **Publicly visible when the instance is casted to {@link IComponentProviderModuleNaked}.**
112
172
  *
package/dist/index.js CHANGED
@@ -19,15 +19,15 @@ function a(e, t) {
19
19
  return s().get(e, t?.isOptional);
20
20
  }
21
21
 
22
- function m(...e) {
22
+ function d(...e) {
23
23
  return s().getMany(...e);
24
24
  }
25
25
 
26
- t(s, "useComponentModule"), t(a, "useInject"), t(m, "useInjectMany");
26
+ t(s, "useComponentModule"), t(a, "useInject"), t(d, "useInjectMany");
27
27
 
28
- import { InjectionScope as c, ProviderModule as p, ProviderModuleHelpers as d } from "@adimm/x-injection";
28
+ import { InjectionScope as c, ProviderModule as m, ProviderModuleHelpers as p } from "@adimm/x-injection";
29
29
 
30
- var u, l = class e extends p {
30
+ var u, l = class e extends m {
31
31
  static {
32
32
  t(this, "ComponentProviderModule");
33
33
  }
@@ -36,7 +36,7 @@ var u, l = class e extends p {
36
36
  initializedFromComponent;
37
37
  constructor(e) {
38
38
  const o = Symbol(`Component${e.identifier.description}`), n = !e.markAsGlobal && (e.contextualizeImports ?? !0), r = n ? new Map : void 0;
39
- super(d.buildInternalConstructorParams({
39
+ super(p.buildInternalConstructorParams({
40
40
  ...e,
41
41
  defaultScope: e.defaultScope ?? c.Singleton,
42
42
  identifier: o,
@@ -48,7 +48,7 @@ var u, l = class e extends p {
48
48
  } : t;
49
49
  })) : e.imports,
50
50
  dynamicExports: t(((e, t) => n ? t.map((e => {
51
- if (!(e instanceof p)) return e;
51
+ if (!(e instanceof m)) return e;
52
52
  return r.get(e.originalIdentifier.toString());
53
53
  })) : t), "dynamicExports")
54
54
  })), this.originalIdentifier = e.identifier, this.hasContextualizedImports = n,
@@ -58,7 +58,7 @@ var u, l = class e extends p {
58
58
  return this;
59
59
  }
60
60
  clone(t) {
61
- const o = t, n = new e(d.buildInternalConstructorParams({
61
+ const o = t, n = new e(p.buildInternalConstructorParams({
62
62
  isAppModule: this.isAppModule,
63
63
  markAsGlobal: this.isMarkedAsGlobal,
64
64
  identifier: Symbol(this.identifier.description.replace("Component", "")),
@@ -73,44 +73,53 @@ var u, l = class e extends p {
73
73
  exports: [ ...this.exports ],
74
74
  ...o
75
75
  }));
76
- return n.initializedFromComponent = this.initializedFromComponent, n;
77
- }
78
- async dispose() {
79
- await super.dispose();
76
+ return n.initializedFromComponent = this.initializedFromComponent, n.registeredBindingSideEffects = new Map(this.registeredBindingSideEffects),
77
+ n;
80
78
  }
81
79
  _createContextualizedComponentInstance(e) {
82
80
  if (this.initializedFromComponent) return this;
83
81
  const t = this.clone().toNaked();
84
- return t.identifier = Symbol(`${e ? `[Parent:${e.description ?? "Unknown"}]` : ""}Contextualized${t.identifier.description}`),
82
+ return t.identifier = Symbol(`${e ? `[Importer:${e.description ?? "Unknown"}]` : ""}Contextualized${t.identifier.description}`),
85
83
  t.initializedFromComponent = !0, t;
86
84
  }
87
85
  };
88
86
 
89
87
  import f from "react";
90
88
 
91
- import { useMemo as h } from "react";
89
+ import { InjectionProviderModuleError as h } from "@adimm/x-injection";
90
+
91
+ import { useMemo as C } from "react";
92
92
 
93
- import { useEffect as C, useRef as x, useState as y } from "react";
93
+ import { useEffect as M, useRef as g, useState as x } from "react";
94
94
 
95
- function M(e) {
96
- const t = x(void 0), o = x(!1), n = x(!1), [, r] = y(0);
97
- o.current && (n.current = !0), C((() => (o.current || (t.current = e(), o.current = !0),
95
+ function v(e) {
96
+ const t = g(void 0), o = g(!1), n = g(!1), [, r] = x(0);
97
+ o.current && (n.current = !0), M((() => (o.current || (t.current = e(), o.current = !0),
98
98
  r((e => e + 1)), () => {
99
99
  n.current && t.current?.();
100
100
  })), []);
101
101
  }
102
102
 
103
- function v(e, t) {
104
- const o = h((() => {
105
- const o = (t ?? e).toNaked();
106
- return o.isMarkedAsGlobal ? o : o._createContextualizedComponentInstance();
107
- }), [ e, t ]);
108
- return M((() => () => {
103
+ function y(e, t) {
104
+ const o = C((() => {
105
+ const {module: o, inject: n} = t ?? {};
106
+ let r = (o ?? e).toNaked();
107
+ if (r.isMarkedAsGlobal && n) throw new h(r, "The 'inject' prop can be used only with modules which are not marked as global!");
108
+ if (r.isMarkedAsGlobal || (r = r._createContextualizedComponentInstance().toNaked()),
109
+ n) {
110
+ const e = new Map(r.registeredSideEffects);
111
+ r.registeredSideEffects.clear(), n.forEach((e => {
112
+ r.__unbind(e), r.moduleUtils.bindToContainer(e, r.defaultScope.native);
113
+ })), r.registeredBindingSideEffects = e;
114
+ }
115
+ return r;
116
+ }), [ e, t?.inject ]);
117
+ return v((() => () => {
109
118
  o.dispose();
110
119
  })), o;
111
120
  }
112
121
 
113
- t(M, "useEffectOnce"), t(v, "useContextualizedModule");
122
+ t(v, "useEffectOnce"), t(y, "useContextualizedModule");
114
123
 
115
124
  import { isFunction as I } from "@adimm/x-injection";
116
125
 
@@ -125,14 +134,14 @@ import { isFunction as I } from "@adimm/x-injection";
125
134
  t(o, "forwardPropsWithModule"), e.forwardPropsWithModule = o;
126
135
  }(u || (u = {}));
127
136
 
128
- var z = f.memo(g);
137
+ var E = f.memo(z);
129
138
 
130
- function P(e, t) {
139
+ function b(e, t) {
131
140
  return o => {
132
- const n = v(e, o.module);
141
+ const n = y(e, o);
133
142
  return f.createElement(r.Provider, {
134
143
  value: n
135
- }, f.createElement(z, {
144
+ }, f.createElement(E, {
136
145
  module: n,
137
146
  componentProps: o,
138
147
  component: t
@@ -140,38 +149,38 @@ function P(e, t) {
140
149
  };
141
150
  }
142
151
 
143
- function g({module: e, component: t, componentProps: o}) {
152
+ function z({module: e, component: t, componentProps: o}) {
144
153
  return f.createElement(f.Fragment, null, t(u.forwardPropsWithModule(t, o, e)));
145
154
  }
146
155
 
147
- t(P, "provideModuleToComponent"), t(g, "_ComponentRenderer");
156
+ t(b, "provideModuleToComponent"), t(z, "_ComponentRenderer");
148
157
 
149
- import b, { useMemo as E } from "react";
158
+ import P, { useMemo as S } from "react";
150
159
 
151
160
  function j({module: e, children: t}) {
152
- const o = t.props ?? {}, n = v(e, o.module), i = E((() => b.cloneElement(t, u.forwardPropsWithModule(t, o, n))), [ o, n ]);
153
- return b.createElement(r.Provider, {
161
+ const o = t.props ?? {}, n = y(e, o), i = S((() => P.cloneElement(t, u.forwardPropsWithModule(t, o, n))), [ o, n ]);
162
+ return P.createElement(r.Provider, {
154
163
  value: n
155
164
  }, i);
156
165
  }
157
166
 
158
167
  t(j, "ProvideModule");
159
168
 
160
- import { useMemo as k } from "react";
169
+ import { useMemo as w } from "react";
161
170
 
162
- import { InjectionProviderModuleError as w } from "@adimm/x-injection";
171
+ import { InjectionProviderModuleError as k } from "@adimm/x-injection";
163
172
 
164
- var S = class e extends w {
173
+ var F = class e extends k {
165
174
  static {
166
175
  t(this, "InjectionHookFactoryError");
167
176
  }
168
177
  name=e.name;
169
178
  };
170
179
 
171
- function F({use: e, inject: t}) {
180
+ function A({use: e, inject: t}) {
172
181
  return o => {
173
- const n = s(), r = k((() => {
174
- if (0 === t.length) throw new S(n, "The 'deps' property array is missing!");
182
+ const n = s(), r = w((() => {
183
+ if (0 === t.length) throw new F(n, "The 'deps' property array is missing!");
175
184
  return n.getMany(...t);
176
185
  }), [ t ]);
177
186
  return e({
@@ -181,6 +190,6 @@ function F({use: e, inject: t}) {
181
190
  };
182
191
  }
183
192
 
184
- t(F, "hookFactory");
193
+ t(A, "hookFactory");
185
194
 
186
- export { l as ComponentProviderModule, j as ProvideModule, r as REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT, F as hookFactory, P as provideModuleToComponent, s as useComponentModule, a as useInject, m as useInjectMany };//# sourceMappingURL=index.js.map
195
+ export { l as ComponentProviderModule, j as ProvideModule, r as REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT, A as hookFactory, b as provideModuleToComponent, s as useComponentModule, a as useInject, d as useInjectMany };//# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../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/core/provide-module/provide-module.arrow-function.tsx","../src/helpers/hooks/use-contextualized-module.ts","../src/helpers/hooks/use-effect-once.ts","../src/helpers/component-provider-module.ts","../src/core/provide-module/provide-module.provider.tsx","../src/core/hook-factory.ts","../src/errors/hook-factory.ts"],"sourcesContent":["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 IProviderModule,\n type IProviderModuleNaked,\n type ProviderModuleOptionsInternal,\n} from '@adimm/x-injection';\n\nimport type { ComponentProviderModuleOptions, 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 originalIdentifier: symbol;\n protected readonly hasContextualizedImports: IComponentProviderModuleNaked['hasContextualizedImports'];\n protected readonly initializedFromComponent: IComponentProviderModuleNaked['initializedFromComponent'];\n\n constructor(options: ComponentProviderModuleOptions) {\n const identifier = Symbol(`Component${options.identifier.description}`);\n const contextualizeImports = options.markAsGlobal ? false : options.contextualizeImports ?? true;\n const contextualizedImportsCache: Map<string, IProviderModule> | undefined = contextualizeImports\n ? new Map()\n : undefined;\n\n super(\n ProviderModuleHelpers.buildInternalConstructorParams({\n ...options,\n defaultScope: options.defaultScope ?? InjectionScope.Singleton,\n identifier: identifier,\n imports: !contextualizeImports\n ? options.imports\n : options.imports?.map((imp) => {\n const module = (typeof imp === 'function' ? imp() : imp) as IComponentProviderModuleNaked;\n /* istanbul ignore next */\n if (!contextualizeImports) return module;\n\n return () => {\n const ctxModule = module._createContextualizedComponentInstance(identifier);\n\n contextualizedImportsCache!.set(module.originalIdentifier.toString(), ctxModule);\n\n return ctxModule;\n };\n }),\n dynamicExports: (_, exports) => {\n if (!contextualizeImports) return exports;\n\n return exports.map((exp) => {\n if (!(exp instanceof ProviderModule)) return exp;\n\n const cachedCtxModule = contextualizedImportsCache!.get(\n (exp as unknown as IComponentProviderModuleNaked).originalIdentifier.toString()\n )!;\n\n return cachedCtxModule;\n });\n },\n })\n );\n\n this.originalIdentifier = options.identifier;\n this.hasContextualizedImports = contextualizeImports;\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?: Partial<ComponentProviderModuleOptions>): IComponentProviderModule {\n const _options = options as ProviderModuleOptionsInternal;\n\n const clonedModule = new ComponentProviderModule(\n ProviderModuleHelpers.buildInternalConstructorParams({\n isAppModule: this.isAppModule,\n markAsGlobal: this.isMarkedAsGlobal,\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 contextualizeImports: this.hasContextualizedImports,\n importedProvidersMap: this.importedProvidersMap,\n imports: [...this.imports],\n providers: [...this.providers],\n exports: [...this.exports],\n ..._options,\n } as ComponentProviderModuleOptions)\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 override async dispose(): Promise<void> {\n await super.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(parentIdentifier?: symbol): IComponentProviderModule {\n if (this.initializedFromComponent) return this;\n\n const ctxModule = this.clone().toNaked();\n\n /* istanbul ignore next */\n //@ts-expect-error Read-only property\n ctxModule.identifier = Symbol(\n `${parentIdentifier ? `[Parent:${parentIdentifier.description ?? 'Unknown'}]` : ''}Contextualized${ctxModule.identifier.description}`\n );\n ctxModule.initializedFromComponent = true;\n\n return ctxModule;\n }\n\n //#endregion\n}\n","import React from 'react';\n\nimport { ComponentProviderModuleHelpers, useContextualizedModule } from '../../helpers';\nimport type { IComponentProviderModule, PropsWithModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\nconst ComponentRenderer = React.memo(_ComponentRenderer);\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<MyComponentProps>(\n * MyComponentModule,\n * ({ firstName, lastName }) => {\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 as any} />\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(ComponentProviderModuleHelpers.forwardPropsWithModule(component, componentProps, module))}</>;\n}\n\nexport type ReactElementWithProviderModule<P extends Record<string, any>> = (p: PropsWithModule<P>) => React.ReactNode;\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 const module = (forwardedModule ?? originalModule).toNaked();\n\n if (module.isMarkedAsGlobal) return module;\n\n return module._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 namespace ComponentProviderModuleHelpers {\n export 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}\n","import React, { useMemo } from 'react';\n\nimport { ComponentProviderModuleHelpers, 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 const component = useMemo(\n () =>\n React.cloneElement(\n children,\n ComponentProviderModuleHelpers.forwardPropsWithModule(children, componentProps, moduleCtx)\n ),\n [componentProps, moduleCtx]\n );\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n {component}\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 { InjectionHookFactoryError } 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 InjectionHookFactoryError(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 { InjectionProviderModuleError } from '@adimm/x-injection';\n\nexport class InjectionHookFactoryError extends InjectionProviderModuleError {\n override name = InjectionHookFactoryError.name;\n}\n"],"mappings":";;;;AAAA,SAASA,iB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AiB,uCAAuC;MAC9F;AAEA,aAAOA,gBAAgBM,QAAO,GAAIR,MAAAA;IACpC,GAAG;MAACA;KAAO;AAEX,WAAOD,KAAK;MAAE,GAAGE;MAAGG,MAAM;WAAIA;;IAAM,CAAA;EACtC;AACF;AAjBgBP;","names":["AppModule","createContext","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","useContext","useComponentModule","useContext","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","useInject","provider","options","componentModule","useComponentModule","get","isOptional","useInjectMany","deps","componentModule","useComponentModule","getMany","InjectionScope","ProviderModule","ProviderModuleHelpers","ComponentProviderModule","ProviderModule","originalIdentifier","hasContextualizedImports","initializedFromComponent","constructor","options","identifier","Symbol","description","contextualizeImports","markAsGlobal","contextualizedImportsCache","Map","undefined","ProviderModuleHelpers","buildInternalConstructorParams","defaultScope","InjectionScope","Singleton","imports","map","imp","module","ctxModule","_createContextualizedComponentInstance","set","toString","dynamicExports","_","exports","exp","cachedCtxModule","get","toNaked","clone","_options","clonedModule","isAppModule","isMarkedAsGlobal","replace","native","onReady","onDispose","importedProvidersMap","providers","dispose","parentIdentifier","React","useMemo","useEffect","useRef","useState","useEffectOnce","effect","destroyFunc","useRef","undefined","effectCalled","renderAfterCalled","forceRerender","useState","current","useEffect","x","useContextualizedModule","originalModule","forwardedModule","ctxModule","useMemo","module","toNaked","isMarkedAsGlobal","_createContextualizedComponentInstance","useEffectOnce","dispose","isFunction","ComponentProviderModuleHelpers","forwardPropsWithModule","component","props","module","isReactElement","result","isFunction","type","ComponentRenderer","React","memo","_ComponentRenderer","provideModuleToComponent","module","component","componentProps","moduleCtx","useContextualizedModule","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","ComponentProviderModuleHelpers","forwardPropsWithModule","React","useMemo","ProvideModule","module","children","componentProps","props","moduleCtx","useContextualizedModule","component","useMemo","React","cloneElement","ComponentProviderModuleHelpers","forwardPropsWithModule","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","useMemo","InjectionProviderModuleError","InjectionHookFactoryError","InjectionProviderModuleError","name","hookFactory","use","hook","inject","p","componentModule","useComponentModule","deps","useMemo","length","InjectionHookFactoryError","getMany"]}
1
+ {"version":3,"sources":["../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/core/provide-module/provide-module.arrow-function.tsx","../src/helpers/hooks/use-contextualized-module.ts","../src/helpers/hooks/use-effect-once.ts","../src/helpers/component-provider-module.ts","../src/core/provide-module/provide-module.provider.tsx","../src/core/hook-factory.ts","../src/errors/hook-factory.ts"],"sourcesContent":["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 IProviderModule,\n type IProviderModuleNaked,\n type ProviderModuleOptionsInternal,\n} from '@adimm/x-injection';\n\nimport type { ComponentProviderModuleOptions, 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 originalIdentifier: symbol;\n protected readonly hasContextualizedImports: IComponentProviderModuleNaked['hasContextualizedImports'];\n protected readonly initializedFromComponent: IComponentProviderModuleNaked['initializedFromComponent'];\n\n constructor(options: ComponentProviderModuleOptions) {\n const identifier = Symbol(`Component${options.identifier.description}`);\n const contextualizeImports = options.markAsGlobal ? false : options.contextualizeImports ?? true;\n const contextualizedImportsCache: Map<string, IProviderModule> | undefined = contextualizeImports\n ? new Map()\n : undefined;\n\n super(\n ProviderModuleHelpers.buildInternalConstructorParams({\n ...options,\n defaultScope: options.defaultScope ?? InjectionScope.Singleton,\n identifier: identifier,\n imports: !contextualizeImports\n ? options.imports\n : options.imports?.map((imp) => {\n const module = (typeof imp === 'function' ? imp() : imp) as IComponentProviderModuleNaked;\n /* istanbul ignore next */\n if (!contextualizeImports) return module;\n\n return () => {\n const ctxModule = module._createContextualizedComponentInstance(identifier);\n\n contextualizedImportsCache!.set(module.originalIdentifier.toString(), ctxModule);\n\n return ctxModule;\n };\n }),\n dynamicExports: (_, exports) => {\n if (!contextualizeImports) return exports;\n\n return exports.map((exp) => {\n if (!(exp instanceof ProviderModule)) return exp;\n\n const cachedCtxModule = contextualizedImportsCache!.get(\n (exp as unknown as IComponentProviderModuleNaked).originalIdentifier.toString()\n )!;\n\n return cachedCtxModule;\n });\n },\n })\n );\n\n this.originalIdentifier = options.identifier;\n this.hasContextualizedImports = contextualizeImports;\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?: Partial<ComponentProviderModuleOptions>): IComponentProviderModule {\n const _options = options as ProviderModuleOptionsInternal;\n\n const clonedModule = new ComponentProviderModule(\n ProviderModuleHelpers.buildInternalConstructorParams({\n isAppModule: this.isAppModule,\n markAsGlobal: this.isMarkedAsGlobal,\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 contextualizeImports: this.hasContextualizedImports,\n importedProvidersMap: this.importedProvidersMap,\n imports: [...this.imports],\n providers: [...this.providers],\n exports: [...this.exports],\n ..._options,\n } as ComponentProviderModuleOptions)\n );\n\n //@ts-expect-error Read-only method.\n clonedModule.initializedFromComponent = this.initializedFromComponent;\n //@ts-expect-error Read-only method.\n clonedModule.registeredBindingSideEffects = new Map(this.registeredBindingSideEffects);\n\n return clonedModule;\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(parentIdentifier?: symbol): IComponentProviderModule {\n if (this.initializedFromComponent) return this;\n\n const ctxModule = this.clone().toNaked();\n\n /* istanbul ignore next */\n //@ts-expect-error Read-only property\n ctxModule.identifier = Symbol(\n `${parentIdentifier ? `[Importer:${parentIdentifier.description ?? 'Unknown'}]` : ''}Contextualized${ctxModule.identifier.description}`\n );\n ctxModule.initializedFromComponent = true;\n\n return ctxModule;\n }\n\n //#endregion\n}\n","import React from 'react';\n\nimport { ComponentProviderModuleHelpers, useContextualizedModule } from '../../helpers';\nimport type { IComponentProviderModule, PropsWithModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\nconst ComponentRenderer = React.memo(_ComponentRenderer);\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<MyComponentProps>(\n * MyComponentModule,\n * ({ firstName, lastName }) => {\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);\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n <ComponentRenderer module={moduleCtx} componentProps={componentProps} component={component as any} />\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(ComponentProviderModuleHelpers.forwardPropsWithModule(component, componentProps, module))}</>;\n}\n\nexport type ReactElementWithProviderModule<P extends Record<string, any>> = (p: PropsWithModule<P>) => React.ReactNode;\n","import { InjectionProviderModuleError } from '@adimm/x-injection';\nimport { useMemo } from 'react';\n\nimport type { IComponentProviderModule, PropsWithModule } from '../../types';\nimport { useEffectOnce } from './use-effect-once';\n\nexport function useContextualizedModule(\n originalModule: IComponentProviderModule,\n componentProps?: PropsWithModule<object>\n): IComponentProviderModule {\n const ctxModule = useMemo(() => {\n /* istanbul ignore next */\n const { module: forwardedModule, inject } = componentProps ?? {};\n let module = (forwardedModule ?? originalModule).toNaked();\n\n if (module.isMarkedAsGlobal && inject) {\n throw new InjectionProviderModuleError(\n module,\n `The 'inject' prop can be used only with modules which are not marked as global!`\n );\n }\n\n if (!module.isMarkedAsGlobal) {\n module = module._createContextualizedComponentInstance().toNaked();\n }\n\n if (inject) {\n const sideEffectsOriginal = new Map(module.registeredSideEffects);\n module.registeredSideEffects.clear();\n\n inject.forEach((provider) => {\n module.__unbind(provider);\n\n module.moduleUtils.bindToContainer(provider, module.defaultScope.native);\n });\n\n //@ts-expect-error Read-only property.\n module.registeredBindingSideEffects = sideEffectsOriginal;\n }\n\n return module;\n }, [originalModule, componentProps?.inject]);\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 namespace ComponentProviderModuleHelpers {\n export 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}\n","import React, { useMemo } from 'react';\n\nimport { ComponentProviderModuleHelpers, 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 * 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 PropsWithModule<object>;\n const moduleCtx = useContextualizedModule(module, componentProps);\n const component = useMemo(\n () =>\n React.cloneElement(\n children,\n ComponentProviderModuleHelpers.forwardPropsWithModule(children, componentProps, moduleCtx)\n ),\n [componentProps, moduleCtx]\n );\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n {component}\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 { InjectionHookFactoryError } 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 InjectionHookFactoryError(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 { InjectionProviderModuleError } from '@adimm/x-injection';\n\nexport class InjectionHookFactoryError extends InjectionProviderModuleError {\n override name = InjectionHookFactoryError.name;\n}\n"],"mappings":";;;;AAAA,SAASA,iBAAiB;AAC1B,SAASC,qBAAqB;AAIvB,IAAMC,4CAA4CD,cAAwCD,SAAAA;;;ACLjG,SAASG,kBAAkB;AAMpB,SAASC,qBAAAA;AACd,SAAOC,WAAWC,yCAAAA;AACpB;AAFgBF;;;ACST,SAASG,UAAaC,UAA4BC,SAA0B;AACjF,QAAMC,kBAAkBC,mBAAAA;AAExB,SAAOD,gBAAgBE,IAAIJ,UAAUC,SAASI,UAAAA;AACh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EO,SAASC,YAAsD,EACpEC,KAAKC,MACLC,OAAM,GACqB;AAC3B,SAAO,CAACC,MAAAA;AACN,UAAMC,kBAAkBC,mBAAAA;AAExB,UAAMC,OAAOC,SAAQ,MAAA;AACnB,UAAIL,OAAOM,WAAW,GAAG;AACvB,cAAM,IAAIC,0BAA0BL,iBAAiB,uCAAuC;MAC9F;AAEA,aAAOA,gBAAgBM,QAAO,GAAIR,MAAAA;IACpC,GAAG;MAACA;KAAO;AAEX,WAAOD,KAAK;MAAE,GAAGE;MAAGG,MAAM;WAAIA;;IAAM,CAAA;EACtC;AACF;AAjBgBP;","names":["AppModule","createContext","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","useContext","useComponentModule","useContext","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","useInject","provider","options","componentModule","useComponentModule","get","isOptional","useInjectMany","deps","componentModule","useComponentModule","getMany","InjectionScope","ProviderModule","ProviderModuleHelpers","ComponentProviderModule","ProviderModule","originalIdentifier","hasContextualizedImports","initializedFromComponent","constructor","options","identifier","Symbol","description","contextualizeImports","markAsGlobal","contextualizedImportsCache","Map","undefined","ProviderModuleHelpers","buildInternalConstructorParams","defaultScope","InjectionScope","Singleton","imports","map","imp","module","ctxModule","_createContextualizedComponentInstance","set","toString","dynamicExports","_","exports","exp","cachedCtxModule","get","toNaked","clone","_options","clonedModule","isAppModule","isMarkedAsGlobal","replace","native","onReady","onDispose","importedProvidersMap","providers","registeredBindingSideEffects","parentIdentifier","React","InjectionProviderModuleError","useMemo","useEffect","useRef","useState","useEffectOnce","effect","destroyFunc","useRef","undefined","effectCalled","renderAfterCalled","forceRerender","useState","current","useEffect","x","useContextualizedModule","originalModule","componentProps","ctxModule","useMemo","module","forwardedModule","inject","toNaked","isMarkedAsGlobal","InjectionProviderModuleError","_createContextualizedComponentInstance","sideEffectsOriginal","Map","registeredSideEffects","clear","forEach","provider","__unbind","moduleUtils","bindToContainer","defaultScope","native","registeredBindingSideEffects","useEffectOnce","dispose","isFunction","ComponentProviderModuleHelpers","forwardPropsWithModule","component","props","module","isReactElement","result","isFunction","type","ComponentRenderer","React","memo","_ComponentRenderer","provideModuleToComponent","module","component","componentProps","moduleCtx","useContextualizedModule","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","ComponentProviderModuleHelpers","forwardPropsWithModule","React","useMemo","ProvideModule","module","children","componentProps","props","moduleCtx","useContextualizedModule","component","useMemo","React","cloneElement","ComponentProviderModuleHelpers","forwardPropsWithModule","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","useMemo","InjectionProviderModuleError","InjectionHookFactoryError","InjectionProviderModuleError","name","hookFactory","use","hook","inject","p","componentModule","useComponentModule","deps","useMemo","length","InjectionHookFactoryError","getMany"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adimm/x-injection-reactjs",
3
3
  "description": "ReactJS integration of the `xInjection` library.",
4
- "version": "0.3.0",
4
+ "version": "0.3.1",
5
5
  "author": "Adi-Marian Mutu",
6
6
  "homepage": "https://github.com/AdiMarianMutu/x-injection-reactjs#readme",
7
7
  "bugs": "https://github.com/AdiMarianMutu/x-injection-reactjs/issues",
@@ -38,7 +38,7 @@
38
38
  "v:bump-major": "npm version major -m \"chore: update lib major version %s\""
39
39
  },
40
40
  "dependencies": {
41
- "@adimm/x-injection": "^0.7.0",
41
+ "@adimm/x-injection": "^0.8.0",
42
42
  "react": ">=18.0.0"
43
43
  },
44
44
  "devDependencies": {