Comparing version 4.2.0 to 4.3.0
@@ -105,13 +105,9 @@ 'use strict'; | ||
function alias(alias, name) { | ||
if (this.$$factories[name] != null) { | ||
this.$$factories[alias] = this.$$factories[name]; | ||
return; | ||
if (this.$$alias[alias] == null || this.$$config.precedence === 'active') { | ||
this.$$alias[alias] = name; | ||
} | ||
if (this.$$factories[alias] != null) { | ||
this.$$factories[name] = this.$$factories[alias]; | ||
return; | ||
if (this.$$alias[name] == null || this.$$config.precedence === 'active') { | ||
this.$$alias[name] = alias; | ||
} | ||
throw new Error(`Cannot create an alias for [${name}|${alias}] as it does not exist`); | ||
} | ||
@@ -202,2 +198,10 @@ | ||
const getFromAlias = (jpex, alias) => { | ||
const name = jpex.$$alias[alias]; | ||
if (name != null) { | ||
return jpex.$$factories[name]; | ||
} | ||
}; | ||
const getFromResolved = (jpex, name) => { | ||
@@ -215,3 +219,3 @@ return jpex.$$resolved[name]; | ||
validateArgs$1(name); | ||
const fns = [getFromResolved, getFromRegistry, getFromGlobal, getFromNodeModules]; | ||
const fns = [getFromResolved, getFromRegistry, getFromAlias, getFromGlobal, getFromNodeModules]; | ||
@@ -382,7 +386,3 @@ while (fns.length) { | ||
if ((_this$$$factories$dep = this.$$factories[dependency]) != null && _this$$$factories$dep.resolved) { | ||
return true; | ||
} | ||
return false; | ||
return ((_this$$$factories$dep = this.$$factories[dependency]) == null ? void 0 : _this$$$factories$dep.resolved) === true; | ||
} | ||
@@ -450,2 +450,3 @@ function allResolved(dependencies) { | ||
$$resolved: {}, | ||
$$alias: parent && inherit ? Object.create(parent.$$alias) : {}, | ||
constant, | ||
@@ -452,0 +453,0 @@ factory, |
@@ -101,13 +101,9 @@ function constant(name, obj) { | ||
function alias(alias, name) { | ||
if (this.$$factories[name] != null) { | ||
this.$$factories[alias] = this.$$factories[name]; | ||
return; | ||
if (this.$$alias[alias] == null || this.$$config.precedence === 'active') { | ||
this.$$alias[alias] = name; | ||
} | ||
if (this.$$factories[alias] != null) { | ||
this.$$factories[name] = this.$$factories[alias]; | ||
return; | ||
if (this.$$alias[name] == null || this.$$config.precedence === 'active') { | ||
this.$$alias[name] = alias; | ||
} | ||
throw new Error(`Cannot create an alias for [${name}|${alias}] as it does not exist`); | ||
} | ||
@@ -198,2 +194,10 @@ | ||
const getFromAlias = (jpex, alias) => { | ||
const name = jpex.$$alias[alias]; | ||
if (name != null) { | ||
return jpex.$$factories[name]; | ||
} | ||
}; | ||
const getFromResolved = (jpex, name) => { | ||
@@ -211,3 +215,3 @@ return jpex.$$resolved[name]; | ||
validateArgs$1(name); | ||
const fns = [getFromResolved, getFromRegistry, getFromGlobal, getFromNodeModules]; | ||
const fns = [getFromResolved, getFromRegistry, getFromAlias, getFromGlobal, getFromNodeModules]; | ||
@@ -378,7 +382,3 @@ while (fns.length) { | ||
if ((_this$$$factories$dep = this.$$factories[dependency]) != null && _this$$$factories$dep.resolved) { | ||
return true; | ||
} | ||
return false; | ||
return ((_this$$$factories$dep = this.$$factories[dependency]) == null ? void 0 : _this$$$factories$dep.resolved) === true; | ||
} | ||
@@ -446,2 +446,3 @@ function allResolved(dependencies) { | ||
$$resolved: {}, | ||
$$alias: parent && inherit ? Object.create(parent.$$alias) : {}, | ||
constant, | ||
@@ -448,0 +449,0 @@ factory, |
@@ -162,13 +162,9 @@ 'use strict'; | ||
function alias(alias, name) { | ||
if (this.$$factories[name] != null) { | ||
this.$$factories[alias] = this.$$factories[name]; | ||
return; | ||
if (this.$$alias[alias] == null || this.$$config.precedence === 'active') { | ||
this.$$alias[alias] = name; | ||
} | ||
if (this.$$factories[alias] != null) { | ||
this.$$factories[name] = this.$$factories[alias]; | ||
return; | ||
if (this.$$alias[name] == null || this.$$config.precedence === 'active') { | ||
this.$$alias[name] = alias; | ||
} | ||
throw new Error("Cannot create an alias for [" + name + "|" + alias + "] as it does not exist"); | ||
} | ||
@@ -259,2 +255,10 @@ | ||
var getFromAlias = function getFromAlias(jpex, alias) { | ||
var name = jpex.$$alias[alias]; | ||
if (name != null) { | ||
return jpex.$$factories[name]; | ||
} | ||
}; | ||
var getFromResolved = function getFromResolved(jpex, name) { | ||
@@ -276,3 +280,3 @@ return jpex.$$resolved[name]; | ||
validateArgs$1(name); | ||
var fns = [getFromResolved, getFromRegistry, getFromGlobal, getFromNodeModules]; | ||
var fns = [getFromResolved, getFromRegistry, getFromAlias, getFromGlobal, getFromNodeModules]; | ||
@@ -446,7 +450,3 @@ while (fns.length) { | ||
if ((_this$$$factories$dep = this.$$factories[dependency]) != null && _this$$$factories$dep.resolved) { | ||
return true; | ||
} | ||
return false; | ||
return ((_this$$$factories$dep = this.$$factories[dependency]) == null ? void 0 : _this$$$factories$dep.resolved) === true; | ||
} | ||
@@ -521,2 +521,3 @@ function allResolved(dependencies) { | ||
$$resolved: {}, | ||
$$alias: parent && inherit ? Object.create(parent.$$alias) : {}, | ||
constant: constant, | ||
@@ -523,0 +524,0 @@ factory: factory, |
@@ -75,2 +75,5 @@ import { Lifecycle, AnyFunction, Dependency, AnyConstructor, Factory, Precedence, NamedParameters } from './'; | ||
}; | ||
$$alias: { | ||
[key: string]: string; | ||
}; | ||
$$config: { | ||
@@ -77,0 +80,0 @@ lifecycle: Lifecycle; |
{ | ||
"name": "jpex", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"description": "Javascript Prototype Extension", | ||
@@ -83,4 +83,4 @@ "main": "dist/cjs/jpex.js", | ||
"dependencies": { | ||
"@jpex-js/babel-plugin": "^1.2.0" | ||
"@jpex-js/babel-plugin": "^1.3.0" | ||
} | ||
} |
@@ -223,2 +223,13 @@ | ||
If a class `implements` an interface, you can actually use it to resolve the class: | ||
```ts | ||
interface IFoo {} | ||
class Foo implements IFoo {} | ||
jpex.service(Foo); | ||
const foo = jpex.resolve<IFoo>(); | ||
``` | ||
#### jpex.alias | ||
@@ -225,0 +236,0 @@ ```ts |
70836
1346
456
Updated@jpex-js/babel-plugin@^1.3.0