@adimm/x-injection-reactjs 0.3.1 → 1.0.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 +188 -103
- package/dist/index.cjs +78 -151
- package/dist/index.d.cts +52 -148
- package/dist/index.d.ts +52 -148
- package/dist/index.js +64 -139
- package/package.json +13 -13
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;A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,UACAS,+BAA+BC,uBAAuBV,UAAUC,gBAAgBE,SAAAA,CAAAA,GAEpF;IAACF;IAAgBE;GAAU;AAG7B,SACE,8BAAAI,QAAA,cAACI,0CAA0CC,UAAQ;IAACC,OAAOV;KACxDE,SAAAA;AAGP;AAlBgBP;;;ACjChB,IAAAgB,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.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;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;EACAC;EACAC;EAEnBC,YAAYC,SAAyC;AACnD,UAAMC,aAAaC,OAAO,YAAYF,QAAQC,WAAWE,WAAW,EAAE;AACtE,UAAMC,uBAAuBJ,QAAQK,eAAe,QAAQL,QAAQI,wBAAwB;AAC5F,UAAME,6BAAuEF,uBACzE,oBAAIG,IAAAA,IACJC;AAEJ,UACEC,sBAAsBC,+BAA+B;MACnD,GAAGV;MACHW,cAAcX,QAAQW,gBAAgBC,eAAeC;MACrDZ;MACAa,SAAS,CAACV,uBAC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A,cAAA,MAAA,UAAA,MAAGD,UAAUO,+BAA+BC,uBAAuBR,WAAWC,gBAAgBF,MAAAA,CAAAA,CAAAA;AACvG;AAVSF;;;AIlDT,OAAOY,UAASC,WAAAA,gBAAe;AAkCxB,SAASC,cAAc,EAAEC,QAAQC,SAAQ,GAA+B;AAE7E,QAAMC,iBAAkBD,SAASE,SAAS,CAAC;AAC3C,QAAMC,YAAYC,wBAAwBL,QAAQE,cAAAA;AAClD,QAAMI,YAAYC,SAChB,MACEC,gBAAAA,OAAMC,aACJR,UACAS,+BAA+BC,uBAAuBV,UAAUC,gBAAgBE,SAAAA,CAAAA,GAEpF;IAACF;IAAgBE;GAAU;AAG7B,SACE,gBAAAI,OAAA,cAACI,0CAA0CC,UAAQ;IAACC,OAAOV;KACxDE,SAAAA;AAGP;AAlBgBP;;;ACjChB,SAASgB,WAAAA,gBAAe;;;ACDxB,SAASC,gCAAAA,qCAAoC;AAEtC,IAAMC,4BAAN,MAAMA,mCAAkCC,8BAAAA;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","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"]}
|