Skip to content

Commit 7634874

Browse files
chore(all): prepare release 0.4.3
1 parent 4a99d4f commit 7634874

File tree

12 files changed

+185
-33
lines changed

12 files changed

+185
-33
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aurelia-dependency-injection",
3-
"version": "0.4.2",
3+
"version": "0.4.3",
44
"description": "A lightweight, extensible dependency injection container for JavaScript.",
55
"keywords": [
66
"aurelia",

dist/amd/container.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
1515
function Container(constructionInfo) {
1616
this.constructionInfo = constructionInfo || new Map();
1717
this.entries = new Map();
18+
this.root = this;
1819
}
1920

2021
_prototypeProperties(Container, null, {
@@ -87,7 +88,13 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
8788
},
8889
autoRegister: {
8990
value: function autoRegister(fn, key) {
90-
var registration = Metadata.on(fn).first(Registration, true);
91+
var registration;
92+
93+
if (fn === null || fn === undefined) {
94+
throw new Error("fn cannot be null or undefined.");
95+
}
96+
97+
registration = Metadata.on(fn).first(Registration, true);
9198

9299
if (registration) {
93100
registration.register(this, key || fn, fn);
@@ -119,6 +126,10 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
119126
value: function get(key) {
120127
var entry;
121128

129+
if (key === null || key === undefined) {
130+
throw new Error("key cannot be null or undefined.");
131+
}
132+
122133
if (key instanceof Resolver) {
123134
return key.get(this);
124135
}
@@ -148,7 +159,13 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
148159
getAll: {
149160
value: function getAll(key) {
150161
var _this = this;
151-
var entry = this.entries.get(key);
162+
var entry;
163+
164+
if (key === null || key === undefined) {
165+
throw new Error("key cannot be null or undefined.");
166+
}
167+
168+
entry = this.entries.get(key);
152169

153170
if (entry !== undefined) {
154171
return entry.map(function (x) {
@@ -168,6 +185,10 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
168185
hasHandler: {
169186
value: function hasHandler(key) {
170187
var checkParent = arguments[1] === undefined ? false : arguments[1];
188+
if (key === null || key === undefined) {
189+
throw new Error("key cannot be null or undefined.");
190+
}
191+
171192
return this.entries.has(key) || checkParent && this.parent && this.parent.hasHandler(key, checkParent);
172193
},
173194
writable: true,
@@ -177,6 +198,7 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
177198
value: function createChild() {
178199
var childContainer = new Container(this.constructionInfo);
179200
childContainer.parent = this;
201+
childContainer.root = this.root;
180202
childContainer.locateParameterInfoElsewhere = this.locateParameterInfoElsewhere;
181203
return childContainer;
182204
},
@@ -213,7 +235,13 @@ define(["exports", "aurelia-metadata", "./metadata", "./util"], function (export
213235
},
214236
getOrCreateEntry: {
215237
value: function getOrCreateEntry(key) {
216-
var entry = this.entries.get(key);
238+
var entry;
239+
240+
if (key === null || key === undefined) {
241+
throw new Error("key cannot be null or undefined.");
242+
}
243+
244+
entry = this.entries.get(key);
217245

218246
if (entry === undefined) {
219247
entry = [];

dist/amd/metadata.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,23 @@ define(["exports"], function (exports) {
4040
return Transient;
4141
})(Registration);
4242
var Singleton = exports.Singleton = (function (Registration) {
43-
function Singleton(key) {
44-
this.key = key;
43+
function Singleton(keyOrRegisterInRoot) {
44+
var registerInRoot = arguments[1] === undefined ? false : arguments[1];
45+
if (typeof keyOrRegisterInRoot === "boolean") {
46+
this.registerInRoot = keyOrRegisterInRoot;
47+
} else {
48+
this.key = keyOrRegisterInRoot;
49+
this.registerInRoot = registerInRoot;
50+
}
4551
}
4652

4753
_inherits(Singleton, Registration);
4854

4955
_prototypeProperties(Singleton, null, {
5056
register: {
5157
value: function register(container, key, fn) {
52-
container.registerSingleton(this.key || key, fn);
58+
var destination = this.registerInRoot ? container.root : container;
59+
destination.registerSingleton(this.key || key, fn);
5360
},
5461
writable: true,
5562
configurable: true

dist/commonjs/container.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var Container = exports.Container = (function () {
1616
function Container(constructionInfo) {
1717
this.constructionInfo = constructionInfo || new Map();
1818
this.entries = new Map();
19+
this.root = this;
1920
}
2021

2122
_prototypeProperties(Container, null, {
@@ -88,7 +89,13 @@ var Container = exports.Container = (function () {
8889
},
8990
autoRegister: {
9091
value: function autoRegister(fn, key) {
91-
var registration = Metadata.on(fn).first(Registration, true);
92+
var registration;
93+
94+
if (fn === null || fn === undefined) {
95+
throw new Error("fn cannot be null or undefined.");
96+
}
97+
98+
registration = Metadata.on(fn).first(Registration, true);
9299

93100
if (registration) {
94101
registration.register(this, key || fn, fn);
@@ -120,6 +127,10 @@ var Container = exports.Container = (function () {
120127
value: function get(key) {
121128
var entry;
122129

130+
if (key === null || key === undefined) {
131+
throw new Error("key cannot be null or undefined.");
132+
}
133+
123134
if (key instanceof Resolver) {
124135
return key.get(this);
125136
}
@@ -149,7 +160,13 @@ var Container = exports.Container = (function () {
149160
getAll: {
150161
value: function getAll(key) {
151162
var _this = this;
152-
var entry = this.entries.get(key);
163+
var entry;
164+
165+
if (key === null || key === undefined) {
166+
throw new Error("key cannot be null or undefined.");
167+
}
168+
169+
entry = this.entries.get(key);
153170

154171
if (entry !== undefined) {
155172
return entry.map(function (x) {
@@ -169,6 +186,10 @@ var Container = exports.Container = (function () {
169186
hasHandler: {
170187
value: function hasHandler(key) {
171188
var checkParent = arguments[1] === undefined ? false : arguments[1];
189+
if (key === null || key === undefined) {
190+
throw new Error("key cannot be null or undefined.");
191+
}
192+
172193
return this.entries.has(key) || checkParent && this.parent && this.parent.hasHandler(key, checkParent);
173194
},
174195
writable: true,
@@ -178,6 +199,7 @@ var Container = exports.Container = (function () {
178199
value: function createChild() {
179200
var childContainer = new Container(this.constructionInfo);
180201
childContainer.parent = this;
202+
childContainer.root = this.root;
181203
childContainer.locateParameterInfoElsewhere = this.locateParameterInfoElsewhere;
182204
return childContainer;
183205
},
@@ -214,7 +236,13 @@ var Container = exports.Container = (function () {
214236
},
215237
getOrCreateEntry: {
216238
value: function getOrCreateEntry(key) {
217-
var entry = this.entries.get(key);
239+
var entry;
240+
241+
if (key === null || key === undefined) {
242+
throw new Error("key cannot be null or undefined.");
243+
}
244+
245+
entry = this.entries.get(key);
218246

219247
if (entry === undefined) {
220248
entry = [];

dist/commonjs/metadata.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,23 @@ var Transient = exports.Transient = (function (Registration) {
3939
return Transient;
4040
})(Registration);
4141
var Singleton = exports.Singleton = (function (Registration) {
42-
function Singleton(key) {
43-
this.key = key;
42+
function Singleton(keyOrRegisterInRoot) {
43+
var registerInRoot = arguments[1] === undefined ? false : arguments[1];
44+
if (typeof keyOrRegisterInRoot === "boolean") {
45+
this.registerInRoot = keyOrRegisterInRoot;
46+
} else {
47+
this.key = keyOrRegisterInRoot;
48+
this.registerInRoot = registerInRoot;
49+
}
4450
}
4551

4652
_inherits(Singleton, Registration);
4753

4854
_prototypeProperties(Singleton, null, {
4955
register: {
5056
value: function register(container, key, fn) {
51-
container.registerSingleton(this.key || key, fn);
57+
var destination = this.registerInRoot ? container.root : container;
58+
destination.registerSingleton(this.key || key, fn);
5259
},
5360
writable: true,
5461
configurable: true

dist/es6/container.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export class Container {
1414
constructor(constructionInfo) {
1515
this.constructionInfo = constructionInfo || new Map();
1616
this.entries = new Map();
17+
this.root = this;
1718
}
1819

1920
/**
@@ -98,8 +99,14 @@ export class Container {
9899
* @param {Object} [key] The key that identifies the dependency at resolution time; usually a constructor function.
99100
*/
100101
autoRegister(fn, key){
101-
var registration = Metadata.on(fn).first(Registration, true);
102-
102+
var registration;
103+
104+
if (fn === null || fn === undefined){
105+
throw new Error('fn cannot be null or undefined.')
106+
}
107+
108+
registration = Metadata.on(fn).first(Registration, true);
109+
103110
if(registration){
104111
registration.register(this, key || fn, fn);
105112
}else{
@@ -141,6 +148,10 @@ export class Container {
141148
get(key) {
142149
var entry;
143150

151+
if (key === null || key === undefined){
152+
throw new Error('key cannot be null or undefined.');
153+
}
154+
144155
if(key instanceof Resolver){
145156
return key.get(this);
146157
}
@@ -173,7 +184,13 @@ export class Container {
173184
* @return {Object[]} Returns an array of the resolved instances.
174185
*/
175186
getAll(key) {
176-
var entry = this.entries.get(key);
187+
var entry;
188+
189+
if (key === null || key === undefined){
190+
throw new Error('key cannot be null or undefined.');
191+
}
192+
193+
entry = this.entries.get(key);
177194

178195
if(entry !== undefined){
179196
return entry.map(x => x(this));
@@ -195,7 +212,11 @@ export class Container {
195212
* @return {Boolean} Returns true if the key has been registred; false otherwise.
196213
*/
197214
hasHandler(key, checkParent=false) {
198-
return this.entries.has(key)
215+
if (key === null || key === undefined){
216+
throw new Error('key cannot be null or undefined.');
217+
}
218+
219+
return this.entries.has(key)
199220
|| (checkParent && this.parent && this.parent.hasHandler(key, checkParent));
200221
}
201222

@@ -208,6 +229,7 @@ export class Container {
208229
createChild(){
209230
var childContainer = new Container(this.constructionInfo);
210231
childContainer.parent = this;
232+
childContainer.root = this.root;
211233
childContainer.locateParameterInfoElsewhere = this.locateParameterInfoElsewhere;
212234
return childContainer;
213235
}
@@ -243,7 +265,13 @@ export class Container {
243265
}
244266

245267
getOrCreateEntry(key) {
246-
var entry = this.entries.get(key);
268+
var entry;
269+
270+
if (key === null || key === undefined){
271+
throw new Error('key cannot be null or undefined.');
272+
}
273+
274+
entry = this.entries.get(key);
247275

248276
if (entry === undefined) {
249277
entry = [];
@@ -255,7 +283,7 @@ export class Container {
255283

256284
getOrCreateConstructionInfo(fn){
257285
var info = this.constructionInfo.get(fn);
258-
286+
259287
if(info === undefined){
260288
info = this.createConstructionInfo(fn);
261289
this.constructionInfo.set(fn, info);
@@ -285,4 +313,4 @@ export class Container {
285313

286314
return info;
287315
}
288-
}
316+
}

dist/es6/metadata.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ export class Transient extends Registration {
5353
* @param {Object} [key] The key to register as.
5454
*/
5555
export class Singleton extends Registration {
56-
constructor(key){
57-
this.key = key;
56+
constructor(keyOrRegisterInRoot, registerInRoot=false){
57+
if(typeof keyOrRegisterInRoot === 'boolean'){
58+
this.registerInRoot = keyOrRegisterInRoot;
59+
}else{
60+
this.key = keyOrRegisterInRoot;
61+
this.registerInRoot = registerInRoot;
62+
}
5863
}
5964

6065
/**
@@ -66,7 +71,8 @@ export class Singleton extends Registration {
6671
* @param {Object} fn The function to register (target of the annotation).
6772
*/
6873
register(container, key, fn){
69-
container.registerSingleton(this.key || key, fn);
74+
var destination = this.registerInRoot ? container.root : container;
75+
destination.registerSingleton(this.key || key, fn);
7076
}
7177
}
7278

@@ -231,7 +237,7 @@ export class Parent extends Resolver {
231237
* @return {Function} Returns the matching instance from the parent container
232238
*/
233239
get(container){
234-
return container.parent
240+
return container.parent
235241
? container.parent.get(this.key)
236242
: null;
237243
}
@@ -247,4 +253,4 @@ export class Parent extends Resolver {
247253
static of(key){
248254
return new Parent(key);
249255
}
250-
}
256+
}

0 commit comments

Comments
 (0)