@wixc3/engine-core
Advanced tools
Comparing version 6.0.2 to 6.1.0
@@ -23,3 +23,3 @@ import { EnvironmentTypes } from '../com/types'; | ||
useContext(contextEnv: keyof MapBy<ENVS, 'env'>): EnvironmentContext; | ||
withContext<I>(): DisposableContext<I>; | ||
withContext<I extends object>(): DisposableContext<I>; | ||
} | ||
@@ -26,0 +26,0 @@ export declare function normEnvVisibility(envVisibility: EnvVisibility): Set<string>; |
import { RuntimeEngine } from '../runtime-engine'; | ||
import { CREATE_RUNTIME, DISPOSE, RUN } from '../symbols'; | ||
import { DisposableContext, DisposeFunction, EntityMap, EnvironmentFilter, FeatureDef, MapToProxyType, PartialFeatureConfig, RunningFeatures, SetupHandler, SomeFeature } from '../types'; | ||
import { ContextHandler, DisposableContext, DisposeFunction, EntityMap, EnvironmentFilter, FeatureDef, MapToProxyType, PartialFeatureConfig, RunningFeatures, SetupHandler, SomeFeature } from '../types'; | ||
/*************** FEATURE ***************/ | ||
@@ -29,5 +29,5 @@ export declare class RuntimeFeature<T extends SomeFeature, Deps extends SomeFeature[], API extends EntityMap> { | ||
use(config: PartialFeatureConfig<API>): [ID, PartialFeatureConfig<API>]; | ||
setupContext<T extends keyof EnvironmentContext>(environmentContext: T, contextHandler: () => EnvironmentContext[T]['type']): this; | ||
setupContext<K extends keyof EnvironmentContext, Env extends EnvironmentFilter>(_env: Env, environmentContext: K, contextHandler: ContextHandler<EnvironmentContext[K]['type'], Env, Deps>): this; | ||
[CREATE_RUNTIME](runningEngine: RuntimeEngine): RuntimeFeature<this, Deps, API>; | ||
} | ||
//# sourceMappingURL=feature.d.ts.map |
@@ -65,3 +65,3 @@ "use strict"; | ||
// context = Context<Interface> | ||
setupContext(environmentContext, contextHandler) { | ||
setupContext(_env, environmentContext, contextHandler) { | ||
const registerdContext = this.contextHandlers.get(environmentContext); | ||
@@ -102,3 +102,3 @@ if (registerdContext) { | ||
for (const [key, contextHandler] of this.contextHandlers) { | ||
const contextValue = contextHandler(); | ||
const contextValue = contextHandler(depsApis); | ||
environmentContext[key] = Object.assign({}, emptyDispose, contextValue); | ||
@@ -105,0 +105,0 @@ } |
@@ -133,2 +133,3 @@ import { TupleToUnion } from 'typescript-type-utils'; | ||
export declare type SetupHandler<EnvFilter extends EnvironmentFilter, ID extends string, Deps extends SomeFeature[], API extends EntityMap, EnvironmentContext extends Record<string, Context<any>>, Filter extends NormalizeEnvironmentFilter<EnvFilter> = NormalizeEnvironmentFilter<EnvFilter>> = (feature: SettingUpFeature<ID, API, Filter>, runningFeatures: RunningFeatures<Deps, Filter>, context: MapRecordType<EnvironmentContext>) => RegisteringFeature<API, Filter>; | ||
export declare type ContextHandler<C, EnvFilter extends EnvironmentFilter, Deps extends SomeFeature[], Filter extends NormalizeEnvironmentFilter<EnvFilter> = NormalizeEnvironmentFilter<EnvFilter>> = (runningFeatures: RunningFeatures<Deps, Filter>) => C; | ||
export declare type PartialFeatureConfig<API> = Partial<MapToPartialType<JustFilter<API, Config<any, any>>>>; | ||
@@ -135,0 +136,0 @@ export declare type TopLevelConfig = Array<[string, object]>; |
{ | ||
"name": "@wixc3/engine-core", | ||
"version": "6.0.2", | ||
"version": "6.1.0", | ||
"main": "cjs/index.js", | ||
@@ -5,0 +5,0 @@ "types": "cjs/index.d.ts", |
@@ -44,3 +44,3 @@ import { EnvironmentTypes } from '../com/types'; | ||
public withContext<I>(): DisposableContext<I> { | ||
public withContext<I extends object>(): DisposableContext<I> { | ||
return { | ||
@@ -47,0 +47,0 @@ type: runtimeType<I & { dispose(): unknown }>(this.env + ' context') |
import { RuntimeEngine } from '../runtime-engine'; | ||
import { CREATE_RUNTIME, DISPOSE, REGISTER_VALUE, RUN, RUN_OPTIONS } from '../symbols'; | ||
import { | ||
ContextHandler, | ||
DisposableContext, | ||
@@ -71,3 +72,3 @@ DisposeFunction, | ||
private setupHandlers = new Set<SetupHandler<Environment, ID, Deps, API, EnvironmentContext>>(); | ||
private contextHandlers = new Map<string | number | symbol, () => unknown>(); | ||
private contextHandlers = new Map<string | number | symbol, ContextHandler<object, EnvironmentFilter, Deps>>(); | ||
constructor(def: FeatureDef<ID, Deps, API, EnvironmentContext>) { | ||
@@ -97,5 +98,6 @@ this.id = def.id; | ||
// context = Context<Interface> | ||
public setupContext<T extends keyof EnvironmentContext>( | ||
environmentContext: T, | ||
contextHandler: () => EnvironmentContext[T]['type'] | ||
public setupContext<K extends keyof EnvironmentContext, Env extends EnvironmentFilter>( | ||
_env: Env, | ||
environmentContext: K, | ||
contextHandler: ContextHandler<EnvironmentContext[K]['type'], Env, Deps> | ||
) { | ||
@@ -153,3 +155,3 @@ const registerdContext = this.contextHandlers.get(environmentContext); | ||
for (const [key, contextHandler] of this.contextHandlers) { | ||
const contextValue = contextHandler(); | ||
const contextValue = contextHandler(depsApis); | ||
environmentContext[key] = { ...emptyDispose, ...contextValue }; | ||
@@ -156,0 +158,0 @@ } |
@@ -207,2 +207,9 @@ import { TupleToUnion } from 'typescript-type-utils'; | ||
export type ContextHandler< | ||
C, | ||
EnvFilter extends EnvironmentFilter, | ||
Deps extends SomeFeature[], | ||
Filter extends NormalizeEnvironmentFilter<EnvFilter> = NormalizeEnvironmentFilter<EnvFilter> | ||
> = (runningFeatures: RunningFeatures<Deps, Filter>) => C; | ||
export type PartialFeatureConfig<API> = Partial<MapToPartialType<JustFilter<API, Config<any, any>>>>; | ||
@@ -209,0 +216,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
256169
4280