@adimm/x-injection-reactjs 0.2.0 → 0.2.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
@@ -1,14 +1,15 @@
1
1
  <h1 align="center">
2
- xInjection ReactJS&nbsp;<a href="https://www.npmjs.com/package/@adimm/x-injection-reactjs" target="__blank" alt="Release Version"><img src="https://img.shields.io/npm/v/@adimm/x-injection-reactjs?color=0476bc&label="></a>
3
- <img src="https://flat.badgen.net/npm/license/@adimm/x-injection-reactjs" alt="License">
2
+ xInjection ReactJS <a href="https://www.npmjs.com/package/@adimm/x-injection-reactjs" target="__blank" alt="Release Version"><img src="https://badgen.net/npm/v/@adimm/x-injection-reactjs"></a>
3
+ <img src="https://badgen.net/npm/license/@adimm/x-injection-reactjs" alt="License">
4
+ <a href="https://app.codecov.io/gh/AdiMarianMutu/x-injection-reactjs" target="__blank" alt="Release Version"><img src="https://badgen.net/codecov/c/github/AdiMarianMutu/x-injection-reactjs"></a>
4
5
  </h1>
5
6
 
6
7
  <p align="center">
7
8
  <a href="https://github.com/AdiMarianMutu/x-injection-reactjs/actions/workflows/ci.yml?query=branch%3Amain" target="__blank"><img src="https://github.com/AdiMarianMutu/x-injection-reactjs/actions/workflows/ci.yml/badge.svg?branch=main"></a>
8
9
  <a href="https://github.com/AdiMarianMutu/x-injection-reactjs/actions/workflows/publish.yml" target="__blank"><img src="https://github.com/AdiMarianMutu/x-injection-reactjs/actions/workflows/publish.yml/badge.svg"></a>
9
10
  <br>
10
- <img src="https://flat.badgen.net/bundlephobia/minzip/@adimm/x-injection-reactjs">
11
- <a href="https://www.npmjs.com/package/@adimm/x-injection-reactjs" target="__blank" alt="Monthly Downloads"><img src="https://flat.badgen.net/npm/dm/@adimm/x-injection-reactjs"></a>
11
+ <img src="https://badgen.net/bundlephobia/minzip/@adimm/x-injection-reactjs">
12
+ <a href="https://www.npmjs.com/package/@adimm/x-injection-reactjs" target="__blank" alt="Monthly Downloads"><img src="https://badgen.net/npm/dm/@adimm/x-injection-reactjs"></a>
12
13
  </p>
13
14
 
14
15
  ## Table of Contents
@@ -25,6 +26,7 @@ xInjection ReactJS&nbsp;<a href="https://www.npmjs.com/package/@adimm/x-injectio
25
26
  - [Hook Injection](#hook-injection)
26
27
  - [Examples](#examples)
27
28
  - [Composable components](#composable-components)
29
+ - [Unit Tests](#unit-tests)
28
30
  - [Documentation](#documentation)
29
31
  - [Contributing](#contributing)
30
32
 
@@ -465,6 +467,50 @@ This should cover the fundamentals of how you can build a scalable UI by using t
465
467
 
466
468
  > **Note:** _Keep in mind that both library ([xInjection](https://www.npmjs.com/package/@adimm/x-injection) & [xInjection ReactJS](https://www.npmjs.com/package/@adimm/x-injection-reactjs)) are still young and being developed, therefore the internals and public API may change in the near future._
467
469
 
470
+ ## Unit Tests
471
+
472
+ It is very easy to create mock modules so you can provide them to your components in your unit tests.
473
+
474
+ ```tsx
475
+ class ApiService {
476
+ constructor(private readonly userService: UserService) {}
477
+
478
+ async sendRequest<T>(location: LocationParams): Promise<T> {
479
+ // Pseudo Implementation
480
+ return this.sendToLocation(user, location);
481
+ }
482
+
483
+ private async sendToLocation(user: User, location: any): Promise<any> {}
484
+ }
485
+
486
+ const ApiModule = new ComponentProviderModule({
487
+ identifier: Symbol('ApiModule'),
488
+ providers: [UserService, ApiService],
489
+ });
490
+
491
+ const ApiModuleMocked = new ComponentProviderModule({
492
+ identifier: Symbol('ApiModule_MOCK'),
493
+ providers: [
494
+ {
495
+ provide: UserService,
496
+ useClass: UserService_Mock,
497
+ },
498
+ {
499
+ provide: ApiService,
500
+ useValue: {
501
+ sendRequest: async (location) => {
502
+ console.log(location);
503
+ },
504
+ },
505
+ },
506
+ ],
507
+ });
508
+
509
+ await act(async () => render(<RealComponent module={ApiModuleMocked} />));
510
+ ```
511
+
512
+ Now what you have to do is just to provide the `ApiModuleMocked` instead of the `ApiModule` 😎
513
+
468
514
  ## Documentation
469
515
 
470
516
  Comprehensive, auto-generated documentation is available at:
package/dist/index.cjs CHANGED
@@ -149,9 +149,9 @@ function I({module: e, children: t}) {
149
149
 
150
150
  s(I, "ProvideModule");
151
151
 
152
- var g = require("react"), R = require("@adimm/x-injection"), F = class e extends R.XInjectionProviderModuleError {
152
+ var g = require("react"), R = require("@adimm/x-injection"), F = class e extends R.InjectionProviderModuleError {
153
153
  static {
154
- s(this, "XInjectionHookFactoryError");
154
+ s(this, "InjectionHookFactoryError");
155
155
  }
156
156
  name=e.name;
157
157
  };
@@ -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/helpers/hooks/use-contextualized-module.ts","../src/helpers/hooks/use-effect-once.ts","../src/helpers/forward-props-with-module.ts","../src/core/provide-module/provide-module.arrow-function.tsx","../src/core/provide-module/provide-module.provider.tsx","../src/core/hook-factory.ts","../src/errors/hook-factory.ts"],"sourcesContent":["export * from './core';\nexport type * from './types';\n","import { AppModule } from '@adimm/x-injection';\nimport { createContext } from 'react';\n\nimport type { IComponentProviderModule } from '../types';\n\nexport const REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT = createContext<IComponentProviderModule>(AppModule as any);\n","import { useContext } from 'react';\n\nimport type { IComponentProviderModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\n/** Can be used to retrieve the {@link IComponentProviderModule} from the current context. */\nexport function useComponentModule(): IComponentProviderModule {\n return useContext(REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT);\n}\n","import type { ProviderToken } from '@adimm/x-injection';\n\nimport { useComponentModule } from './use-component-module';\n\n/**\n * Low-level hook which can be used to resolve a single dependency from the current\n * context module.\n *\n * **Note:** _In order to better modularize your code-base, you should strive to create custom hooks by using the_\n * _`hookFactory` method to compose a custom hook._\n *\n * @param provider The {@link ProviderToken}.\n * @param options See {@link UseInjectOptions}.\n * @returns The resolved {@link T | dependency}.\n */\nexport function useInject<T>(provider: ProviderToken<T>, options?: UseInjectOptions): T {\n const componentModule = useComponentModule();\n\n return componentModule.get(provider, options?.isOptional);\n}\n\nexport type UseInjectOptions = {\n /** When set to `false` _(default)_ an exception will be thrown when the `providerOrIdentifier` isn't bound. */\n isOptional?: boolean;\n};\n","import type { ProviderModuleGetManyParam, ProviderModuleGetManySignature, ProviderToken } from '@adimm/x-injection';\n\nimport { useComponentModule } from './use-component-module';\n\n/**\n * Low-level hook which can be used to resolve multiple dependencies at once from the current\n * context module.\n *\n * **Note:** _In order to better modularize your code-base, you should strive to create custom hooks by using the_\n * _`hookFactory` method to compose a custom hook._\n *\n * @param deps Either one or more {@link ProviderToken}.\n * @returns Tuple containing the {@link D | dependencies}.\n */\nexport function useInjectMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>(\n ...deps: D | unknown[]\n): ProviderModuleGetManySignature<D> {\n const componentModule = useComponentModule();\n\n return componentModule.getMany(...deps);\n}\n","import {\n InjectionScope,\n ProviderModule,\n ProviderModuleHelpers,\n type CloneParams,\n type IProviderModuleNaked,\n type ProviderModuleOptions,\n} from '@adimm/x-injection';\n\nimport type { IComponentProviderModule, IComponentProviderModuleNaked } from '../types';\n\n/** A superset of the {@link ProviderModule} used to integrate within a `React` component. */\nexport class ComponentProviderModule extends ProviderModule implements IComponentProviderModule {\n protected readonly _initializedFromComponent: IComponentProviderModuleNaked['_initializedFromComponent'];\n\n constructor(options: ProviderModuleOptions) {\n super(\n ProviderModuleHelpers.buildInternalConstructorParams({\n ...options,\n defaultScope: options.defaultScope ?? InjectionScope.Singleton,\n identifier: Symbol(`Component${options.identifier.description}`),\n })\n );\n\n this._initializedFromComponent = false;\n }\n\n override toNaked(): IComponentProviderModuleNaked & IProviderModuleNaked {\n return this as any;\n }\n\n /* istanbul ignore next */\n override clone(options?: CloneParams): IComponentProviderModule {\n let providers = [...this.providers];\n\n if (options?.providersMap) {\n providers = providers.map((provider) => options.providersMap!(provider, this));\n }\n\n const clonedModule = new ComponentProviderModule(\n ProviderModuleHelpers.buildInternalConstructorParams({\n isAppModule: this.isAppModule,\n identifier: Symbol(this.identifier.description!.replace('Component', '')),\n defaultScope: this.defaultScope.native,\n dynamicExports: this.dynamicExports,\n onReady: this.onReady,\n onDispose: this.onDispose,\n importedProvidersMap: options?.importedProvidersMap,\n imports: [...this.imports],\n providers,\n exports: [...this.exports],\n })\n );\n\n //@ts-expect-error Read-only method.\n clonedModule._initializedFromComponent = this._initializedFromComponent;\n\n return clonedModule;\n }\n\n /* istanbul ignore next */\n dispose(): void {\n this._dispose();\n }\n\n //#region IComponentProviderModuleNaked methods\n\n /**\n * **Publicly visible when the instance is casted to {@link IComponentProviderModuleNaked}.**\n *\n * See {@link IComponentProviderModuleNaked._createContextualizedComponentInstance}.\n */\n protected _createContextualizedComponentInstance(): IComponentProviderModule {\n if (this._initializedFromComponent) return this;\n\n const ctxModule = this.clone().toNaked();\n\n //@ts-expect-error Read-only property\n ctxModule.identifier = Symbol(`Contextualized${ctxModule.identifier.description}`);\n ctxModule._initializedFromComponent = true;\n\n return ctxModule;\n }\n\n //#endregion\n}\n","import { useMemo } from 'react';\n\nimport type { IComponentProviderModule } from '../../types';\nimport { useEffectOnce } from './use-effect-once';\n\nexport function useContextualizedModule(\n originalModule: IComponentProviderModule,\n forwardedModule?: IComponentProviderModule\n): IComponentProviderModule {\n const ctxModule = useMemo(() => {\n return (forwardedModule ?? originalModule).toNaked()._createContextualizedComponentInstance();\n }, [originalModule, forwardedModule]);\n\n useEffectOnce(() => {\n return () => {\n ctxModule.dispose();\n };\n });\n\n return ctxModule;\n}\n","import { useEffect, useRef, useState } from 'react';\n\n// Credits: https://stackoverflow.com/a/74000921\n\n/** Custom {@link useEffect} hook which will be run once. _(In `StrictMode` as well)_ */\nexport function useEffectOnce(effect: () => React.EffectCallback) {\n const destroyFunc = useRef<React.EffectCallback>(undefined);\n const effectCalled = useRef(false);\n const renderAfterCalled = useRef(false);\n const [, forceRerender] = useState(0);\n\n if (effectCalled.current) renderAfterCalled.current = true;\n\n useEffect(() => {\n // only execute the effect first time around\n if (!effectCalled.current) {\n destroyFunc.current = effect();\n effectCalled.current = true;\n }\n\n // this forces one render after the effect is run\n forceRerender((x) => x + 1);\n\n return () => {\n // if the comp didn't render since the useEffect was called,\n // we know it's the dummy React cycle\n if (!renderAfterCalled.current) return;\n\n destroyFunc.current?.();\n };\n }, []);\n}\n","import { isFunction } from '@adimm/x-injection';\n\nimport type { ReactElementWithProviderModule } from '../core';\nimport type { IComponentProviderModule, PropsWithModule } from '../types';\n\nexport function forwardPropsWithModule<P extends Record<string, any>>(\n component: ReactElementWithProviderModule<P> | React.ReactElement,\n props: Record<string, any>,\n module: IComponentProviderModule\n): PropsWithModule<P> {\n const isReactElement = typeof component === 'object' && 'type' in component;\n\n const result = {\n ...props,\n } as any;\n\n if ((isReactElement && isFunction(component.type)) || isFunction(component)) {\n result['module'] = module;\n }\n\n return result;\n}\n","import { forwardPropsWithModule, useContextualizedModule } from '../../helpers';\nimport type { IComponentProviderModule, PropsWithModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\n/**\n * Can be used to easily provide a {@link module} to any component.\n *\n * @example\n * ```tsx\n * interface MyComponentProps {\n * firstName: string;\n * lastName: string;\n * }\n *\n * export const MyComponent = provideModuleToComponent(\n * MyComponentModule,\n * ({ firstName, lastName }: MyComponentProps) => {\n * const service = useInject(MyComponentService);\n *\n * return <h1>Hello {service.computeUserName(firstName, lastName)}!</h1>\n * }\n * );\n *\n * function App() {\n * return <MyComponent firstName={'John'} lastName={'Doe'} />;\n * }\n * ```\n *\n * @param module The {@link IComponentProviderModule | Module} which should be consumed by the {@link component}.\n * @returns The provided {@link toComponent | Component}.\n */\nexport function provideModuleToComponent<\n P extends Record<string, any>,\n C extends ReactElementWithProviderModule<P> = ReactElementWithProviderModule<P>,\n>(module: IComponentProviderModule, component: ReactElementWithProviderModule<P>): C {\n return ((componentProps: PropsWithModule<P>) => {\n const moduleCtx = useContextualizedModule(module, componentProps.module);\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n <ComponentRenderer module={moduleCtx} componentProps={componentProps} component={component} />\n </REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider>\n );\n }) as any;\n}\n\nfunction ComponentRenderer<P extends Record<string, any>>({\n module,\n component,\n componentProps,\n}: {\n module: IComponentProviderModule;\n component: ReactElementWithProviderModule<P>;\n componentProps: P;\n}) {\n return <>{component(forwardPropsWithModule(component, componentProps, module))}</>;\n}\n\nexport type ReactElementWithProviderModule<P extends Record<string, any>> = (p: PropsWithModule<P>) => React.ReactNode;\n","import React from 'react';\n\nimport { forwardPropsWithModule, useContextualizedModule } from '../../helpers';\nimport type { IComponentProviderModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\n/**\n * Can be used to easily provide a {@link module} to any component.\n *\n * @example\n * ```tsx\n * interface MyComponentProps {\n * firstName: string;\n * lastName: string;\n * }\n *\n * function MyComponent({ firstName, lastName }: MyComponentProps) {\n * const service = useInject(MyComponentService);\n *\n * return <h1>Hello {service.computeUserName(firstName, lastName)}!</h1>\n * }\n *\n * function App() {\n * return (\n * <ProvideModule module={MyComponentModule}>\n * <MyComponent firstName={'John'} lastName={'Doe'} />\n * </ProvideModule>\n * );\n * }\n * ```\n *\n * @param param0 See {@link ProvideModuleFunctionParams}.\n * @returns The provided {@link toComponent | Component}.\n */\nexport function ProvideModule({ module, children }: ProvideModuleFunctionParams) {\n /* istanbul ignore next */\n const componentProps = (children.props ?? {}) as any;\n const moduleCtx = useContextualizedModule(module, componentProps.module);\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n {React.cloneElement(children, forwardPropsWithModule(children, componentProps, moduleCtx))}\n </REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider>\n );\n}\n\nexport interface ProvideModuleFunctionParams {\n /** The {@link IComponentProviderModule | Module} which should be consumed by the {@link children | component}. */\n module: IComponentProviderModule;\n\n children: React.ReactElement;\n}\n","import type { ProviderToken } from '@adimm/x-injection';\nimport { useMemo } from 'react';\n\nimport { XInjectionHookFactoryError } from '../errors';\nimport { useComponentModule } from './hooks';\n\nexport function hookFactory<P extends HookParams, D extends any[], T>({\n use: hook,\n inject,\n}: HookFactoryParams<P, D, T>): (p: P) => T {\n return (p: P) => {\n const componentModule = useComponentModule();\n\n const deps = useMemo(() => {\n if (inject.length === 0) {\n throw new XInjectionHookFactoryError(componentModule, `The 'deps' property array is missing!`);\n }\n\n return componentModule.getMany(...inject);\n }, [inject]);\n\n return hook({ ...p, deps: [...deps] } as any);\n };\n}\n\nexport interface HookFactoryParams<P extends HookParams, D extends any[], T> {\n use: HookWithProviderModuleDependencies<P, D, T>;\n inject: ProviderToken[];\n}\n\nexport type HookWithProviderModuleDependencies<P extends HookParams, D extends any[], T> = (p: HookWithDeps<P, D>) => T;\n\nexport type HookWithDeps<P extends HookParams, D extends any[]> = P & {\n /** Array containing the resolved dependencies from the component context. */\n deps: D;\n};\n\ntype HookParams = Record<string, any> | void;\n","import { XInjectionProviderModuleError } from '@adimm/x-injection';\n\nexport class XInjectionHookFactoryError extends XInjectionProviderModuleError {\n name = XInjectionHookFactoryError.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,kBAAkBC,mBAAAA;AAExB,SAAOD,gBAAgBE,IAAIJ,UAAUC,SAASI,UAAAA;AAChD;AAJgBN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ECTION_PROVIDER_MODULE_CONTEXT","createContext","AppModule","import_react","useComponentModule","useContext","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","useInject","provider","options","componentModule","useComponentModule","get","isOptional","useInjectMany","deps","componentModule","useComponentModule","getMany","import_x_injection","ComponentProviderModule","ProviderModule","_initializedFromComponent","constructor","options","ProviderModuleHelpers","buildInternalConstructorParams","defaultScope","InjectionScope","Singleton","identifier","Symbol","description","toNaked","clone","providers","providersMap","map","provider","clonedModule","isAppModule","replace","native","dynamicExports","onReady","onDispose","importedProvidersMap","imports","exports","dispose","_dispose","_createContextualizedComponentInstance","ctxModule","import_react","import_react","useEffectOnce","effect","destroyFunc","useRef","undefined","effectCalled","renderAfterCalled","forceRerender","useState","current","useEffect","x","useContextualizedModule","originalModule","forwardedModule","ctxModule","useMemo","toNaked","_createContextualizedComponentInstance","useEffectOnce","dispose","import_x_injection","forwardPropsWithModule","component","props","module","isReactElement","result","isFunction","type","provideModuleToComponent","module","component","componentProps","moduleCtx","useContextualizedModule","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","ComponentRenderer","forwardPropsWithModule","import_react","ProvideModule","module","children","componentProps","props","moduleCtx","useContextualizedModule","React","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","cloneElement","forwardPropsWithModule","import_react","import_x_injection","XInjectionHookFactoryError","XInjectionProviderModuleError","name","hookFactory","use","hook","inject","p","componentModule","useComponentModule","deps","useMemo","length","XInjectionHookFactoryError","getMany"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/core/react-context.ts","../src/core/hooks/use-component-module.ts","../src/core/hooks/use-inject.ts","../src/core/hooks/use-inject-many.ts","../src/core/component-provider-module.ts","../src/helpers/hooks/use-contextualized-module.ts","../src/helpers/hooks/use-effect-once.ts","../src/helpers/forward-props-with-module.ts","../src/core/provide-module/provide-module.arrow-function.tsx","../src/core/provide-module/provide-module.provider.tsx","../src/core/hook-factory.ts","../src/errors/hook-factory.ts"],"sourcesContent":["export * from './core';\nexport type * from './types';\n","import { AppModule } from '@adimm/x-injection';\nimport { createContext } from 'react';\n\nimport type { IComponentProviderModule } from '../types';\n\nexport const REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT = createContext<IComponentProviderModule>(AppModule as any);\n","import { useContext } from 'react';\n\nimport type { IComponentProviderModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\n/** Can be used to retrieve the {@link IComponentProviderModule} from the current context. */\nexport function useComponentModule(): IComponentProviderModule {\n return useContext(REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT);\n}\n","import type { ProviderToken } from '@adimm/x-injection';\n\nimport { useComponentModule } from './use-component-module';\n\n/**\n * Low-level hook which can be used to resolve a single dependency from the current\n * context module.\n *\n * **Note:** _In order to better modularize your code-base, you should strive to create custom hooks by using the_\n * _`hookFactory` method to compose a custom hook._\n *\n * @param provider The {@link ProviderToken}.\n * @param options See {@link UseInjectOptions}.\n * @returns The resolved {@link T | dependency}.\n */\nexport function useInject<T>(provider: ProviderToken<T>, options?: UseInjectOptions): T {\n const componentModule = useComponentModule();\n\n return componentModule.get(provider, options?.isOptional);\n}\n\nexport type UseInjectOptions = {\n /** When set to `false` _(default)_ an exception will be thrown when the `providerOrIdentifier` isn't bound. */\n isOptional?: boolean;\n};\n","import type { ProviderModuleGetManyParam, ProviderModuleGetManySignature, ProviderToken } from '@adimm/x-injection';\n\nimport { useComponentModule } from './use-component-module';\n\n/**\n * Low-level hook which can be used to resolve multiple dependencies at once from the current\n * context module.\n *\n * **Note:** _In order to better modularize your code-base, you should strive to create custom hooks by using the_\n * _`hookFactory` method to compose a custom hook._\n *\n * @param deps Either one or more {@link ProviderToken}.\n * @returns Tuple containing the {@link D | dependencies}.\n */\nexport function useInjectMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>(\n ...deps: D | unknown[]\n): ProviderModuleGetManySignature<D> {\n const componentModule = useComponentModule();\n\n return componentModule.getMany(...deps);\n}\n","import {\n InjectionScope,\n ProviderModule,\n ProviderModuleHelpers,\n type CloneParams,\n type IProviderModuleNaked,\n type ProviderModuleOptions,\n} from '@adimm/x-injection';\n\nimport type { IComponentProviderModule, IComponentProviderModuleNaked } from '../types';\n\n/** A superset of the {@link ProviderModule} used to integrate within a `React` component. */\nexport class ComponentProviderModule extends ProviderModule implements IComponentProviderModule {\n protected readonly _initializedFromComponent: IComponentProviderModuleNaked['_initializedFromComponent'];\n\n constructor(options: ProviderModuleOptions) {\n super(\n ProviderModuleHelpers.buildInternalConstructorParams({\n ...options,\n defaultScope: options.defaultScope ?? InjectionScope.Singleton,\n identifier: Symbol(`Component${options.identifier.description}`),\n })\n );\n\n this._initializedFromComponent = false;\n }\n\n override toNaked(): IComponentProviderModuleNaked & IProviderModuleNaked {\n return this as any;\n }\n\n /* istanbul ignore next */\n override clone(options?: CloneParams): IComponentProviderModule {\n let providers = [...this.providers];\n\n if (options?.providersMap) {\n providers = providers.map((provider) => options.providersMap!(provider, this));\n }\n\n const clonedModule = new ComponentProviderModule(\n ProviderModuleHelpers.buildInternalConstructorParams({\n isAppModule: this.isAppModule,\n identifier: Symbol(this.identifier.description!.replace('Component', '')),\n defaultScope: this.defaultScope.native,\n dynamicExports: this.dynamicExports,\n onReady: this.onReady,\n onDispose: this.onDispose,\n importedProvidersMap: options?.importedProvidersMap,\n imports: [...this.imports],\n providers,\n exports: [...this.exports],\n })\n );\n\n //@ts-expect-error Read-only method.\n clonedModule._initializedFromComponent = this._initializedFromComponent;\n\n return clonedModule;\n }\n\n /* istanbul ignore next */\n dispose(): void {\n this._dispose();\n }\n\n //#region IComponentProviderModuleNaked methods\n\n /**\n * **Publicly visible when the instance is casted to {@link IComponentProviderModuleNaked}.**\n *\n * See {@link IComponentProviderModuleNaked._createContextualizedComponentInstance}.\n */\n protected _createContextualizedComponentInstance(): IComponentProviderModule {\n if (this._initializedFromComponent) return this;\n\n const ctxModule = this.clone().toNaked();\n\n //@ts-expect-error Read-only property\n ctxModule.identifier = Symbol(`Contextualized${ctxModule.identifier.description}`);\n ctxModule._initializedFromComponent = true;\n\n return ctxModule;\n }\n\n //#endregion\n}\n","import { useMemo } from 'react';\n\nimport type { IComponentProviderModule } from '../../types';\nimport { useEffectOnce } from './use-effect-once';\n\nexport function useContextualizedModule(\n originalModule: IComponentProviderModule,\n forwardedModule?: IComponentProviderModule\n): IComponentProviderModule {\n const ctxModule = useMemo(() => {\n return (forwardedModule ?? originalModule).toNaked()._createContextualizedComponentInstance();\n }, [originalModule, forwardedModule]);\n\n useEffectOnce(() => {\n return () => {\n ctxModule.dispose();\n };\n });\n\n return ctxModule;\n}\n","import { useEffect, useRef, useState } from 'react';\n\n// Credits: https://stackoverflow.com/a/74000921\n\n/** Custom {@link useEffect} hook which will be run once. _(In `StrictMode` as well)_ */\nexport function useEffectOnce(effect: () => React.EffectCallback) {\n const destroyFunc = useRef<React.EffectCallback>(undefined);\n const effectCalled = useRef(false);\n const renderAfterCalled = useRef(false);\n const [, forceRerender] = useState(0);\n\n if (effectCalled.current) renderAfterCalled.current = true;\n\n useEffect(() => {\n // only execute the effect first time around\n if (!effectCalled.current) {\n destroyFunc.current = effect();\n effectCalled.current = true;\n }\n\n // this forces one render after the effect is run\n forceRerender((x) => x + 1);\n\n return () => {\n // if the comp didn't render since the useEffect was called,\n // we know it's the dummy React cycle\n if (!renderAfterCalled.current) return;\n\n destroyFunc.current?.();\n };\n }, []);\n}\n","import { isFunction } from '@adimm/x-injection';\n\nimport type { ReactElementWithProviderModule } from '../core';\nimport type { IComponentProviderModule, PropsWithModule } from '../types';\n\nexport function forwardPropsWithModule<P extends Record<string, any>>(\n component: ReactElementWithProviderModule<P> | React.ReactElement,\n props: Record<string, any>,\n module: IComponentProviderModule\n): PropsWithModule<P> {\n const isReactElement = typeof component === 'object' && 'type' in component;\n\n const result = {\n ...props,\n } as any;\n\n if ((isReactElement && isFunction(component.type)) || isFunction(component)) {\n result['module'] = module;\n }\n\n return result;\n}\n","import { forwardPropsWithModule, useContextualizedModule } from '../../helpers';\nimport type { IComponentProviderModule, PropsWithModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\n/**\n * Can be used to easily provide a {@link module} to any component.\n *\n * @example\n * ```tsx\n * interface MyComponentProps {\n * firstName: string;\n * lastName: string;\n * }\n *\n * export const MyComponent = provideModuleToComponent(\n * MyComponentModule,\n * ({ firstName, lastName }: MyComponentProps) => {\n * const service = useInject(MyComponentService);\n *\n * return <h1>Hello {service.computeUserName(firstName, lastName)}!</h1>\n * }\n * );\n *\n * function App() {\n * return <MyComponent firstName={'John'} lastName={'Doe'} />;\n * }\n * ```\n *\n * @param module The {@link IComponentProviderModule | Module} which should be consumed by the {@link component}.\n * @returns The provided {@link toComponent | Component}.\n */\nexport function provideModuleToComponent<\n P extends Record<string, any>,\n C extends ReactElementWithProviderModule<P> = ReactElementWithProviderModule<P>,\n>(module: IComponentProviderModule, component: ReactElementWithProviderModule<P>): C {\n return ((componentProps: PropsWithModule<P>) => {\n const moduleCtx = useContextualizedModule(module, componentProps.module);\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n <ComponentRenderer module={moduleCtx} componentProps={componentProps} component={component} />\n </REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider>\n );\n }) as any;\n}\n\nfunction ComponentRenderer<P extends Record<string, any>>({\n module,\n component,\n componentProps,\n}: {\n module: IComponentProviderModule;\n component: ReactElementWithProviderModule<P>;\n componentProps: P;\n}) {\n return <>{component(forwardPropsWithModule(component, componentProps, module))}</>;\n}\n\nexport type ReactElementWithProviderModule<P extends Record<string, any>> = (p: PropsWithModule<P>) => React.ReactNode;\n","import React from 'react';\n\nimport { forwardPropsWithModule, useContextualizedModule } from '../../helpers';\nimport type { IComponentProviderModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\n/**\n * Can be used to easily provide a {@link module} to any component.\n *\n * @example\n * ```tsx\n * interface MyComponentProps {\n * firstName: string;\n * lastName: string;\n * }\n *\n * function MyComponent({ firstName, lastName }: MyComponentProps) {\n * const service = useInject(MyComponentService);\n *\n * return <h1>Hello {service.computeUserName(firstName, lastName)}!</h1>\n * }\n *\n * function App() {\n * return (\n * <ProvideModule module={MyComponentModule}>\n * <MyComponent firstName={'John'} lastName={'Doe'} />\n * </ProvideModule>\n * );\n * }\n * ```\n *\n * @param param0 See {@link ProvideModuleFunctionParams}.\n * @returns The provided {@link toComponent | Component}.\n */\nexport function ProvideModule({ module, children }: ProvideModuleFunctionParams) {\n /* istanbul ignore next */\n const componentProps = (children.props ?? {}) as any;\n const moduleCtx = useContextualizedModule(module, componentProps.module);\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n {React.cloneElement(children, forwardPropsWithModule(children, componentProps, moduleCtx))}\n </REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider>\n );\n}\n\nexport interface ProvideModuleFunctionParams {\n /** The {@link IComponentProviderModule | Module} which should be consumed by the {@link children | component}. */\n module: IComponentProviderModule;\n\n children: React.ReactElement;\n}\n","import type { ProviderToken } from '@adimm/x-injection';\nimport { useMemo } from 'react';\n\nimport { 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,kBAAkBC,mBAAAA;AAExB,SAAOD,gBAAgBE,IAAIJ,UAAUC,SAASI,UAAAA;AAChD;AAJgBN;;;ACDT,SAASO,iBACXC,MAAmB;AAEtB,QAAMC,kBAAkBC,mBAAAA;AAExB,SAAOD,gBAAgBE,QAAO,GAAIH,IAAAA;AACpC;AANgBD;;;ACdhB,IAAAK,sBAOO;AAKA,IAAMC,0BAAN,MAAMA,iCAAgCC,mCAAAA;EAZ7C,OAY6CA;;;EACxBC;EAEnBC,YAAYC,SAAgC;AAC1C,UACEC,0CAAsBC,+BAA+B;MACnD,GAAGF;MACHG,cAAcH,QAAQG,gBAAgBC,mCAAeC;MACrDC,YAAYC,OAAO,YAAYP,QAAQM,WAAWE,WAAW,EAAE;IACjE,CAAA,CAAA;AAGF,SAAKV,4BAA4B;EACnC;EAESW,UAAgE;AACvE,WAAO;EACT;;EAGSC,MAAMV,SAAiD;AAC9D,QAAIW,YAAY;SAAI,KAAKA;;AAEzB,QAAIX,SAASY,cAAc;AACzBD,kBAAYA,UAAUE,IAAI,CAACC,aAAad,QAAQY,aAAcE,UAAU,IAAI,CAAA;IAC9E;AAEA,UAAMC,eAAe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AUC,gBAAgBE,SAAAA,CAAAA,CAAAA;AAGrF;AAVgBL;;;ACjChB,IAAAa,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","_initializedFromComponent","constructor","options","ProviderModuleHelpers","buildInternalConstructorParams","defaultScope","InjectionScope","Singleton","identifier","Symbol","description","toNaked","clone","providers","providersMap","map","provider","clonedModule","isAppModule","replace","native","dynamicExports","onReady","onDispose","importedProvidersMap","imports","exports","dispose","_dispose","_createContextualizedComponentInstance","ctxModule","import_react","import_react","useEffectOnce","effect","destroyFunc","useRef","undefined","effectCalled","renderAfterCalled","forceRerender","useState","current","useEffect","x","useContextualizedModule","originalModule","forwardedModule","ctxModule","useMemo","toNaked","_createContextualizedComponentInstance","useEffectOnce","dispose","import_x_injection","forwardPropsWithModule","component","props","module","isReactElement","result","isFunction","type","provideModuleToComponent","module","component","componentProps","moduleCtx","useContextualizedModule","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","ComponentRenderer","forwardPropsWithModule","import_react","ProvideModule","module","children","componentProps","props","moduleCtx","useContextualizedModule","React","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","cloneElement","forwardPropsWithModule","import_react","import_x_injection","InjectionHookFactoryError","InjectionProviderModuleError","name","hookFactory","use","hook","inject","p","componentModule","useComponentModule","deps","useMemo","length","InjectionHookFactoryError","getMany"]}
package/dist/index.js CHANGED
@@ -133,11 +133,11 @@ t(E, "ProvideModule");
133
133
 
134
134
  import { useMemo as F } from "react";
135
135
 
136
- import { XInjectionProviderModuleError as _ } from "@adimm/x-injection";
136
+ import { InjectionProviderModuleError as _ } from "@adimm/x-injection";
137
137
 
138
138
  var b = class e extends _ {
139
139
  static {
140
- t(this, "XInjectionHookFactoryError");
140
+ t(this, "InjectionHookFactoryError");
141
141
  }
142
142
  name=e.name;
143
143
  };
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/helpers/hooks/use-contextualized-module.ts","../src/helpers/hooks/use-effect-once.ts","../src/helpers/forward-props-with-module.ts","../src/core/provide-module/provide-module.arrow-function.tsx","../src/core/provide-module/provide-module.provider.tsx","../src/core/hook-factory.ts","../src/errors/hook-factory.ts"],"sourcesContent":["import { AppModule } from '@adimm/x-injection';\nimport { createContext } from 'react';\n\nimport type { IComponentProviderModule } from '../types';\n\nexport const REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT = createContext<IComponentProviderModule>(AppModule as any);\n","import { useContext } from 'react';\n\nimport type { IComponentProviderModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\n/** Can be used to retrieve the {@link IComponentProviderModule} from the current context. */\nexport function useComponentModule(): IComponentProviderModule {\n return useContext(REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT);\n}\n","import type { ProviderToken } from '@adimm/x-injection';\n\nimport { useComponentModule } from './use-component-module';\n\n/**\n * Low-level hook which can be used to resolve a single dependency from the current\n * context module.\n *\n * **Note:** _In order to better modularize your code-base, you should strive to create custom hooks by using the_\n * _`hookFactory` method to compose a custom hook._\n *\n * @param provider The {@link ProviderToken}.\n * @param options See {@link UseInjectOptions}.\n * @returns The resolved {@link T | dependency}.\n */\nexport function useInject<T>(provider: ProviderToken<T>, options?: UseInjectOptions): T {\n const componentModule = useComponentModule();\n\n return componentModule.get(provider, options?.isOptional);\n}\n\nexport type UseInjectOptions = {\n /** When set to `false` _(default)_ an exception will be thrown when the `providerOrIdentifier` isn't bound. */\n isOptional?: boolean;\n};\n","import type { ProviderModuleGetManyParam, ProviderModuleGetManySignature, ProviderToken } from '@adimm/x-injection';\n\nimport { useComponentModule } from './use-component-module';\n\n/**\n * Low-level hook which can be used to resolve multiple dependencies at once from the current\n * context module.\n *\n * **Note:** _In order to better modularize your code-base, you should strive to create custom hooks by using the_\n * _`hookFactory` method to compose a custom hook._\n *\n * @param deps Either one or more {@link ProviderToken}.\n * @returns Tuple containing the {@link D | dependencies}.\n */\nexport function useInjectMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>(\n ...deps: D | unknown[]\n): ProviderModuleGetManySignature<D> {\n const componentModule = useComponentModule();\n\n return componentModule.getMany(...deps);\n}\n","import {\n InjectionScope,\n ProviderModule,\n ProviderModuleHelpers,\n type CloneParams,\n type IProviderModuleNaked,\n type ProviderModuleOptions,\n} from '@adimm/x-injection';\n\nimport type { IComponentProviderModule, IComponentProviderModuleNaked } from '../types';\n\n/** A superset of the {@link ProviderModule} used to integrate within a `React` component. */\nexport class ComponentProviderModule extends ProviderModule implements IComponentProviderModule {\n protected readonly _initializedFromComponent: IComponentProviderModuleNaked['_initializedFromComponent'];\n\n constructor(options: ProviderModuleOptions) {\n super(\n ProviderModuleHelpers.buildInternalConstructorParams({\n ...options,\n defaultScope: options.defaultScope ?? InjectionScope.Singleton,\n identifier: Symbol(`Component${options.identifier.description}`),\n })\n );\n\n this._initializedFromComponent = false;\n }\n\n override toNaked(): IComponentProviderModuleNaked & IProviderModuleNaked {\n return this as any;\n }\n\n /* istanbul ignore next */\n override clone(options?: CloneParams): IComponentProviderModule {\n let providers = [...this.providers];\n\n if (options?.providersMap) {\n providers = providers.map((provider) => options.providersMap!(provider, this));\n }\n\n const clonedModule = new ComponentProviderModule(\n ProviderModuleHelpers.buildInternalConstructorParams({\n isAppModule: this.isAppModule,\n identifier: Symbol(this.identifier.description!.replace('Component', '')),\n defaultScope: this.defaultScope.native,\n dynamicExports: this.dynamicExports,\n onReady: this.onReady,\n onDispose: this.onDispose,\n importedProvidersMap: options?.importedProvidersMap,\n imports: [...this.imports],\n providers,\n exports: [...this.exports],\n })\n );\n\n //@ts-expect-error Read-only method.\n clonedModule._initializedFromComponent = this._initializedFromComponent;\n\n return clonedModule;\n }\n\n /* istanbul ignore next */\n dispose(): void {\n this._dispose();\n }\n\n //#region IComponentProviderModuleNaked methods\n\n /**\n * **Publicly visible when the instance is casted to {@link IComponentProviderModuleNaked}.**\n *\n * See {@link IComponentProviderModuleNaked._createContextualizedComponentInstance}.\n */\n protected _createContextualizedComponentInstance(): IComponentProviderModule {\n if (this._initializedFromComponent) return this;\n\n const ctxModule = this.clone().toNaked();\n\n //@ts-expect-error Read-only property\n ctxModule.identifier = Symbol(`Contextualized${ctxModule.identifier.description}`);\n ctxModule._initializedFromComponent = true;\n\n return ctxModule;\n }\n\n //#endregion\n}\n","import { useMemo } from 'react';\n\nimport type { IComponentProviderModule } from '../../types';\nimport { useEffectOnce } from './use-effect-once';\n\nexport function useContextualizedModule(\n originalModule: IComponentProviderModule,\n forwardedModule?: IComponentProviderModule\n): IComponentProviderModule {\n const ctxModule = useMemo(() => {\n return (forwardedModule ?? originalModule).toNaked()._createContextualizedComponentInstance();\n }, [originalModule, forwardedModule]);\n\n useEffectOnce(() => {\n return () => {\n ctxModule.dispose();\n };\n });\n\n return ctxModule;\n}\n","import { useEffect, useRef, useState } from 'react';\n\n// Credits: https://stackoverflow.com/a/74000921\n\n/** Custom {@link useEffect} hook which will be run once. _(In `StrictMode` as well)_ */\nexport function useEffectOnce(effect: () => React.EffectCallback) {\n const destroyFunc = useRef<React.EffectCallback>(undefined);\n const effectCalled = useRef(false);\n const renderAfterCalled = useRef(false);\n const [, forceRerender] = useState(0);\n\n if (effectCalled.current) renderAfterCalled.current = true;\n\n useEffect(() => {\n // only execute the effect first time around\n if (!effectCalled.current) {\n destroyFunc.current = effect();\n effectCalled.current = true;\n }\n\n // this forces one render after the effect is run\n forceRerender((x) => x + 1);\n\n return () => {\n // if the comp didn't render since the useEffect was called,\n // we know it's the dummy React cycle\n if (!renderAfterCalled.current) return;\n\n destroyFunc.current?.();\n };\n }, []);\n}\n","import { isFunction } from '@adimm/x-injection';\n\nimport type { ReactElementWithProviderModule } from '../core';\nimport type { IComponentProviderModule, PropsWithModule } from '../types';\n\nexport function forwardPropsWithModule<P extends Record<string, any>>(\n component: ReactElementWithProviderModule<P> | React.ReactElement,\n props: Record<string, any>,\n module: IComponentProviderModule\n): PropsWithModule<P> {\n const isReactElement = typeof component === 'object' && 'type' in component;\n\n const result = {\n ...props,\n } as any;\n\n if ((isReactElement && isFunction(component.type)) || isFunction(component)) {\n result['module'] = module;\n }\n\n return result;\n}\n","import { forwardPropsWithModule, useContextualizedModule } from '../../helpers';\nimport type { IComponentProviderModule, PropsWithModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\n/**\n * Can be used to easily provide a {@link module} to any component.\n *\n * @example\n * ```tsx\n * interface MyComponentProps {\n * firstName: string;\n * lastName: string;\n * }\n *\n * export const MyComponent = provideModuleToComponent(\n * MyComponentModule,\n * ({ firstName, lastName }: MyComponentProps) => {\n * const service = useInject(MyComponentService);\n *\n * return <h1>Hello {service.computeUserName(firstName, lastName)}!</h1>\n * }\n * );\n *\n * function App() {\n * return <MyComponent firstName={'John'} lastName={'Doe'} />;\n * }\n * ```\n *\n * @param module The {@link IComponentProviderModule | Module} which should be consumed by the {@link component}.\n * @returns The provided {@link toComponent | Component}.\n */\nexport function provideModuleToComponent<\n P extends Record<string, any>,\n C extends ReactElementWithProviderModule<P> = ReactElementWithProviderModule<P>,\n>(module: IComponentProviderModule, component: ReactElementWithProviderModule<P>): C {\n return ((componentProps: PropsWithModule<P>) => {\n const moduleCtx = useContextualizedModule(module, componentProps.module);\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n <ComponentRenderer module={moduleCtx} componentProps={componentProps} component={component} />\n </REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider>\n );\n }) as any;\n}\n\nfunction ComponentRenderer<P extends Record<string, any>>({\n module,\n component,\n componentProps,\n}: {\n module: IComponentProviderModule;\n component: ReactElementWithProviderModule<P>;\n componentProps: P;\n}) {\n return <>{component(forwardPropsWithModule(component, componentProps, module))}</>;\n}\n\nexport type ReactElementWithProviderModule<P extends Record<string, any>> = (p: PropsWithModule<P>) => React.ReactNode;\n","import React from 'react';\n\nimport { forwardPropsWithModule, useContextualizedModule } from '../../helpers';\nimport type { IComponentProviderModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\n/**\n * Can be used to easily provide a {@link module} to any component.\n *\n * @example\n * ```tsx\n * interface MyComponentProps {\n * firstName: string;\n * lastName: string;\n * }\n *\n * function MyComponent({ firstName, lastName }: MyComponentProps) {\n * const service = useInject(MyComponentService);\n *\n * return <h1>Hello {service.computeUserName(firstName, lastName)}!</h1>\n * }\n *\n * function App() {\n * return (\n * <ProvideModule module={MyComponentModule}>\n * <MyComponent firstName={'John'} lastName={'Doe'} />\n * </ProvideModule>\n * );\n * }\n * ```\n *\n * @param param0 See {@link ProvideModuleFunctionParams}.\n * @returns The provided {@link toComponent | Component}.\n */\nexport function ProvideModule({ module, children }: ProvideModuleFunctionParams) {\n /* istanbul ignore next */\n const componentProps = (children.props ?? {}) as any;\n const moduleCtx = useContextualizedModule(module, componentProps.module);\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n {React.cloneElement(children, forwardPropsWithModule(children, componentProps, moduleCtx))}\n </REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider>\n );\n}\n\nexport interface ProvideModuleFunctionParams {\n /** The {@link IComponentProviderModule | Module} which should be consumed by the {@link children | component}. */\n module: IComponentProviderModule;\n\n children: React.ReactElement;\n}\n","import type { ProviderToken } from '@adimm/x-injection';\nimport { useMemo } from 'react';\n\nimport { XInjectionHookFactoryError } from '../errors';\nimport { useComponentModule } from './hooks';\n\nexport function hookFactory<P extends HookParams, D extends any[], T>({\n use: hook,\n inject,\n}: HookFactoryParams<P, D, T>): (p: P) => T {\n return (p: P) => {\n const componentModule = useComponentModule();\n\n const deps = useMemo(() => {\n if (inject.length === 0) {\n throw new XInjectionHookFactoryError(componentModule, `The 'deps' property array is missing!`);\n }\n\n return componentModule.getMany(...inject);\n }, [inject]);\n\n return hook({ ...p, deps: [...deps] } as any);\n };\n}\n\nexport interface HookFactoryParams<P extends HookParams, D extends any[], T> {\n use: HookWithProviderModuleDependencies<P, D, T>;\n inject: ProviderToken[];\n}\n\nexport type HookWithProviderModuleDependencies<P extends HookParams, D extends any[], T> = (p: HookWithDeps<P, D>) => T;\n\nexport type HookWithDeps<P extends HookParams, D extends any[]> = P & {\n /** Array containing the resolved dependencies from the component context. */\n deps: D;\n};\n\ntype HookParams = Record<string, any> | void;\n","import { XInjectionProviderModuleError } from '@adimm/x-injection';\n\nexport class XInjectionHookFactoryError extends XInjectionProviderModuleError {\n name = XInjectionHookFactoryError.name;\n}\n"],"mappings":";;;;AAAA,SAASA,iBAAiB;AAC1B,SAASC,qBAAqB;AAIvB,IAAMC,4CAA4CD,cAAwCD,SAAAA;;;ACLjG,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2BAA2BL,iBAAiB,uCAAuC;MAC/F;AAEA,aAAOA,gBAAgBM,QAAO,GAAIR,MAAAA;IACpC,GAAG;MAACA;KAAO;AAEX,WAAOD,KAAK;MAAE,GAAGE;MAAGG,MAAM;WAAIA;;IAAM,CAAA;EACtC;AACF;AAjBgBP;","names":["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","_initializedFromComponent","constructor","options","ProviderModuleHelpers","buildInternalConstructorParams","defaultScope","InjectionScope","Singleton","identifier","Symbol","description","toNaked","clone","providers","providersMap","map","provider","clonedModule","isAppModule","replace","native","dynamicExports","onReady","onDispose","importedProvidersMap","imports","exports","dispose","_dispose","_createContextualizedComponentInstance","ctxModule","useMemo","useEffect","useRef","useState","useEffectOnce","effect","destroyFunc","useRef","undefined","effectCalled","renderAfterCalled","forceRerender","useState","current","useEffect","x","useContextualizedModule","originalModule","forwardedModule","ctxModule","useMemo","toNaked","_createContextualizedComponentInstance","useEffectOnce","dispose","isFunction","forwardPropsWithModule","component","props","module","isReactElement","result","isFunction","type","provideModuleToComponent","module","component","componentProps","moduleCtx","useContextualizedModule","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","ComponentRenderer","forwardPropsWithModule","React","ProvideModule","module","children","componentProps","props","moduleCtx","useContextualizedModule","React","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","cloneElement","forwardPropsWithModule","useMemo","XInjectionProviderModuleError","XInjectionHookFactoryError","XInjectionProviderModuleError","name","hookFactory","use","hook","inject","p","componentModule","useComponentModule","deps","useMemo","length","XInjectionHookFactoryError","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/helpers/hooks/use-contextualized-module.ts","../src/helpers/hooks/use-effect-once.ts","../src/helpers/forward-props-with-module.ts","../src/core/provide-module/provide-module.arrow-function.tsx","../src/core/provide-module/provide-module.provider.tsx","../src/core/hook-factory.ts","../src/errors/hook-factory.ts"],"sourcesContent":["import { AppModule } from '@adimm/x-injection';\nimport { createContext } from 'react';\n\nimport type { IComponentProviderModule } from '../types';\n\nexport const REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT = createContext<IComponentProviderModule>(AppModule as any);\n","import { useContext } from 'react';\n\nimport type { IComponentProviderModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\n/** Can be used to retrieve the {@link IComponentProviderModule} from the current context. */\nexport function useComponentModule(): IComponentProviderModule {\n return useContext(REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT);\n}\n","import type { ProviderToken } from '@adimm/x-injection';\n\nimport { useComponentModule } from './use-component-module';\n\n/**\n * Low-level hook which can be used to resolve a single dependency from the current\n * context module.\n *\n * **Note:** _In order to better modularize your code-base, you should strive to create custom hooks by using the_\n * _`hookFactory` method to compose a custom hook._\n *\n * @param provider The {@link ProviderToken}.\n * @param options See {@link UseInjectOptions}.\n * @returns The resolved {@link T | dependency}.\n */\nexport function useInject<T>(provider: ProviderToken<T>, options?: UseInjectOptions): T {\n const componentModule = useComponentModule();\n\n return componentModule.get(provider, options?.isOptional);\n}\n\nexport type UseInjectOptions = {\n /** When set to `false` _(default)_ an exception will be thrown when the `providerOrIdentifier` isn't bound. */\n isOptional?: boolean;\n};\n","import type { ProviderModuleGetManyParam, ProviderModuleGetManySignature, ProviderToken } from '@adimm/x-injection';\n\nimport { useComponentModule } from './use-component-module';\n\n/**\n * Low-level hook which can be used to resolve multiple dependencies at once from the current\n * context module.\n *\n * **Note:** _In order to better modularize your code-base, you should strive to create custom hooks by using the_\n * _`hookFactory` method to compose a custom hook._\n *\n * @param deps Either one or more {@link ProviderToken}.\n * @returns Tuple containing the {@link D | dependencies}.\n */\nexport function useInjectMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>(\n ...deps: D | unknown[]\n): ProviderModuleGetManySignature<D> {\n const componentModule = useComponentModule();\n\n return componentModule.getMany(...deps);\n}\n","import {\n InjectionScope,\n ProviderModule,\n ProviderModuleHelpers,\n type CloneParams,\n type IProviderModuleNaked,\n type ProviderModuleOptions,\n} from '@adimm/x-injection';\n\nimport type { IComponentProviderModule, IComponentProviderModuleNaked } from '../types';\n\n/** A superset of the {@link ProviderModule} used to integrate within a `React` component. */\nexport class ComponentProviderModule extends ProviderModule implements IComponentProviderModule {\n protected readonly _initializedFromComponent: IComponentProviderModuleNaked['_initializedFromComponent'];\n\n constructor(options: ProviderModuleOptions) {\n super(\n ProviderModuleHelpers.buildInternalConstructorParams({\n ...options,\n defaultScope: options.defaultScope ?? InjectionScope.Singleton,\n identifier: Symbol(`Component${options.identifier.description}`),\n })\n );\n\n this._initializedFromComponent = false;\n }\n\n override toNaked(): IComponentProviderModuleNaked & IProviderModuleNaked {\n return this as any;\n }\n\n /* istanbul ignore next */\n override clone(options?: CloneParams): IComponentProviderModule {\n let providers = [...this.providers];\n\n if (options?.providersMap) {\n providers = providers.map((provider) => options.providersMap!(provider, this));\n }\n\n const clonedModule = new ComponentProviderModule(\n ProviderModuleHelpers.buildInternalConstructorParams({\n isAppModule: this.isAppModule,\n identifier: Symbol(this.identifier.description!.replace('Component', '')),\n defaultScope: this.defaultScope.native,\n dynamicExports: this.dynamicExports,\n onReady: this.onReady,\n onDispose: this.onDispose,\n importedProvidersMap: options?.importedProvidersMap,\n imports: [...this.imports],\n providers,\n exports: [...this.exports],\n })\n );\n\n //@ts-expect-error Read-only method.\n clonedModule._initializedFromComponent = this._initializedFromComponent;\n\n return clonedModule;\n }\n\n /* istanbul ignore next */\n dispose(): void {\n this._dispose();\n }\n\n //#region IComponentProviderModuleNaked methods\n\n /**\n * **Publicly visible when the instance is casted to {@link IComponentProviderModuleNaked}.**\n *\n * See {@link IComponentProviderModuleNaked._createContextualizedComponentInstance}.\n */\n protected _createContextualizedComponentInstance(): IComponentProviderModule {\n if (this._initializedFromComponent) return this;\n\n const ctxModule = this.clone().toNaked();\n\n //@ts-expect-error Read-only property\n ctxModule.identifier = Symbol(`Contextualized${ctxModule.identifier.description}`);\n ctxModule._initializedFromComponent = true;\n\n return ctxModule;\n }\n\n //#endregion\n}\n","import { useMemo } from 'react';\n\nimport type { IComponentProviderModule } from '../../types';\nimport { useEffectOnce } from './use-effect-once';\n\nexport function useContextualizedModule(\n originalModule: IComponentProviderModule,\n forwardedModule?: IComponentProviderModule\n): IComponentProviderModule {\n const ctxModule = useMemo(() => {\n return (forwardedModule ?? originalModule).toNaked()._createContextualizedComponentInstance();\n }, [originalModule, forwardedModule]);\n\n useEffectOnce(() => {\n return () => {\n ctxModule.dispose();\n };\n });\n\n return ctxModule;\n}\n","import { useEffect, useRef, useState } from 'react';\n\n// Credits: https://stackoverflow.com/a/74000921\n\n/** Custom {@link useEffect} hook which will be run once. _(In `StrictMode` as well)_ */\nexport function useEffectOnce(effect: () => React.EffectCallback) {\n const destroyFunc = useRef<React.EffectCallback>(undefined);\n const effectCalled = useRef(false);\n const renderAfterCalled = useRef(false);\n const [, forceRerender] = useState(0);\n\n if (effectCalled.current) renderAfterCalled.current = true;\n\n useEffect(() => {\n // only execute the effect first time around\n if (!effectCalled.current) {\n destroyFunc.current = effect();\n effectCalled.current = true;\n }\n\n // this forces one render after the effect is run\n forceRerender((x) => x + 1);\n\n return () => {\n // if the comp didn't render since the useEffect was called,\n // we know it's the dummy React cycle\n if (!renderAfterCalled.current) return;\n\n destroyFunc.current?.();\n };\n }, []);\n}\n","import { isFunction } from '@adimm/x-injection';\n\nimport type { ReactElementWithProviderModule } from '../core';\nimport type { IComponentProviderModule, PropsWithModule } from '../types';\n\nexport function forwardPropsWithModule<P extends Record<string, any>>(\n component: ReactElementWithProviderModule<P> | React.ReactElement,\n props: Record<string, any>,\n module: IComponentProviderModule\n): PropsWithModule<P> {\n const isReactElement = typeof component === 'object' && 'type' in component;\n\n const result = {\n ...props,\n } as any;\n\n if ((isReactElement && isFunction(component.type)) || isFunction(component)) {\n result['module'] = module;\n }\n\n return result;\n}\n","import { forwardPropsWithModule, useContextualizedModule } from '../../helpers';\nimport type { IComponentProviderModule, PropsWithModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\n/**\n * Can be used to easily provide a {@link module} to any component.\n *\n * @example\n * ```tsx\n * interface MyComponentProps {\n * firstName: string;\n * lastName: string;\n * }\n *\n * export const MyComponent = provideModuleToComponent(\n * MyComponentModule,\n * ({ firstName, lastName }: MyComponentProps) => {\n * const service = useInject(MyComponentService);\n *\n * return <h1>Hello {service.computeUserName(firstName, lastName)}!</h1>\n * }\n * );\n *\n * function App() {\n * return <MyComponent firstName={'John'} lastName={'Doe'} />;\n * }\n * ```\n *\n * @param module The {@link IComponentProviderModule | Module} which should be consumed by the {@link component}.\n * @returns The provided {@link toComponent | Component}.\n */\nexport function provideModuleToComponent<\n P extends Record<string, any>,\n C extends ReactElementWithProviderModule<P> = ReactElementWithProviderModule<P>,\n>(module: IComponentProviderModule, component: ReactElementWithProviderModule<P>): C {\n return ((componentProps: PropsWithModule<P>) => {\n const moduleCtx = useContextualizedModule(module, componentProps.module);\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n <ComponentRenderer module={moduleCtx} componentProps={componentProps} component={component} />\n </REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider>\n );\n }) as any;\n}\n\nfunction ComponentRenderer<P extends Record<string, any>>({\n module,\n component,\n componentProps,\n}: {\n module: IComponentProviderModule;\n component: ReactElementWithProviderModule<P>;\n componentProps: P;\n}) {\n return <>{component(forwardPropsWithModule(component, componentProps, module))}</>;\n}\n\nexport type ReactElementWithProviderModule<P extends Record<string, any>> = (p: PropsWithModule<P>) => React.ReactNode;\n","import React from 'react';\n\nimport { forwardPropsWithModule, useContextualizedModule } from '../../helpers';\nimport type { IComponentProviderModule } from '../../types';\nimport { REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT } from '../react-context';\n\n/**\n * Can be used to easily provide a {@link module} to any component.\n *\n * @example\n * ```tsx\n * interface MyComponentProps {\n * firstName: string;\n * lastName: string;\n * }\n *\n * function MyComponent({ firstName, lastName }: MyComponentProps) {\n * const service = useInject(MyComponentService);\n *\n * return <h1>Hello {service.computeUserName(firstName, lastName)}!</h1>\n * }\n *\n * function App() {\n * return (\n * <ProvideModule module={MyComponentModule}>\n * <MyComponent firstName={'John'} lastName={'Doe'} />\n * </ProvideModule>\n * );\n * }\n * ```\n *\n * @param param0 See {@link ProvideModuleFunctionParams}.\n * @returns The provided {@link toComponent | Component}.\n */\nexport function ProvideModule({ module, children }: ProvideModuleFunctionParams) {\n /* istanbul ignore next */\n const componentProps = (children.props ?? {}) as any;\n const moduleCtx = useContextualizedModule(module, componentProps.module);\n\n return (\n <REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider value={moduleCtx}>\n {React.cloneElement(children, forwardPropsWithModule(children, componentProps, moduleCtx))}\n </REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT.Provider>\n );\n}\n\nexport interface ProvideModuleFunctionParams {\n /** The {@link IComponentProviderModule | Module} which should be consumed by the {@link children | component}. */\n module: IComponentProviderModule;\n\n children: React.ReactElement;\n}\n","import type { ProviderToken } from '@adimm/x-injection';\nimport { useMemo } from 'react';\n\nimport { 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;AAChD;AAJgBN;;;ACDT,SAASO,iBACXC,MAAmB;AAEtB,QAAMC,kBAAkBC,mBAAAA;AAExB,SAAOD,gBAAgBE,QAAO,GAAIH,IAAAA;AACpC;AANgBD;;;ACdhB,SACEK,gBACAC,gBACAC,6BAIK;AAKA,IAAMC,0BAAN,MAAMA,iCAAgCC,eAAAA;EAZ7C,OAY6CA;;;EACxBC;EAEnBC,YAAYC,SAAgC;AAC1C,UACEC,sBAAsBC,+BAA+B;MACnD,GAAGF;MACHG,cAAcH,QAAQG,gBAAgBC,eAAeC;MACrDC,YAAYC,OAAO,YAAYP,QAAQM,WAAWE,WAAW,EAAE;IACjE,CAAA,CAAA;AAGF,SAAKV,4BAA4B;EACnC;EAESW,UAAgE;AACvE,WAAO;EACT;;EAGSC,MAA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YAAYC,wBAAwBL,QAAQE,eAAeF,MAAM;AAEvE,SACE,gBAAAM,OAAA,cAACC,0CAA0CC,UAAQ;IAACC,OAAOL;KACxDE,gBAAAA,OAAMI,aAAaT,UAAUU,uBAAuBV,UAAUC,gBAAgBE,SAAAA,CAAAA,CAAAA;AAGrF;AAVgBL;;;ACjChB,SAASa,WAAAA,gBAAe;;;ACDxB,SAASC,oCAAoC;AAEtC,IAAMC,4BAAN,MAAMA,mCAAkCC,6BAAAA;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,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","_initializedFromComponent","constructor","options","ProviderModuleHelpers","buildInternalConstructorParams","defaultScope","InjectionScope","Singleton","identifier","Symbol","description","toNaked","clone","providers","providersMap","map","provider","clonedModule","isAppModule","replace","native","dynamicExports","onReady","onDispose","importedProvidersMap","imports","exports","dispose","_dispose","_createContextualizedComponentInstance","ctxModule","useMemo","useEffect","useRef","useState","useEffectOnce","effect","destroyFunc","useRef","undefined","effectCalled","renderAfterCalled","forceRerender","useState","current","useEffect","x","useContextualizedModule","originalModule","forwardedModule","ctxModule","useMemo","toNaked","_createContextualizedComponentInstance","useEffectOnce","dispose","isFunction","forwardPropsWithModule","component","props","module","isReactElement","result","isFunction","type","provideModuleToComponent","module","component","componentProps","moduleCtx","useContextualizedModule","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","ComponentRenderer","forwardPropsWithModule","React","ProvideModule","module","children","componentProps","props","moduleCtx","useContextualizedModule","React","REACT_X_INJECTION_PROVIDER_MODULE_CONTEXT","Provider","value","cloneElement","forwardPropsWithModule","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.2.0",
4
+ "version": "0.2.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",
@@ -37,7 +37,7 @@
37
37
  "v:bump-major": "npm version major -m \"chore: update lib major version %s\""
38
38
  },
39
39
  "dependencies": {
40
- "@adimm/x-injection": "^0.5.1",
40
+ "@adimm/x-injection": "^0.5.2",
41
41
  "react": ">=18.0.0"
42
42
  },
43
43
  "devDependencies": {