@forestadmin/context
Advanced tools
Comparing version 1.34.5 to 1.35.0
{ | ||
"name": "@forestadmin/context", | ||
"version": "1.34.5", | ||
"version": "1.35.0", | ||
"description": "Minimal context management helper for applications and libraries.", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -152,3 +152,3 @@ const Metadata = require('./metadata'); | ||
this._metadata.add(path, name, 'class', Class, options); | ||
const instance = this._instanciate(Class, options); | ||
const instance = this._instanciate(path, name, Class, options); | ||
this._setNewValue(name, instance, options); | ||
@@ -173,6 +173,11 @@ return this; | ||
_instanciate(Class, { map } = {}) { | ||
const RealClass = Class.toString().startsWith('class') ? Class : Class(); | ||
if (!map) return new RealClass(this.get()); | ||
return new RealClass(this._mapContext(map)); | ||
_instanciate(path, name, FunctionFactory, { map } = {}) { | ||
try { | ||
const isClass = FunctionFactory.toString().startsWith('class'); | ||
const ClassToInstanciate = isClass ? FunctionFactory : FunctionFactory(); | ||
const localContext = map ? this._mapContext(map) : this.get(); | ||
return new ClassToInstanciate(localContext); | ||
} catch (cause) { | ||
throw new Error(`instanciating a value for path "${path}/${name}"`, { cause }); | ||
} | ||
} | ||
@@ -179,0 +184,0 @@ |
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
61482
695