@northern/di 1.0.3 → 2.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 +24 -23
- package/lib/index.d.ts +7 -0
- package/lib/index.js +42 -62
- package/package.json +15 -15
- package/.npmingore +0 -1
- package/di.sublime-project +0 -8
- package/di.sublime-workspace +0 -825
- package/src/index.js +0 -43
- package/src/index.test.js +0 -6
- package/yarn.lock +0 -3577
package/src/index.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export default class Container {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.services = {}
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
service(name, callback, lazy = false) {
|
|
8
|
-
if (this.services[name]) {
|
|
9
|
-
throw new Error(`Service with name '${name}' already exists.`)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (lazy) {
|
|
13
|
-
this.services[name] = (container) => {
|
|
14
|
-
return this.services[name] = callback.call(null, container)
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
this.services[name] = callback.call(null, this)
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
factory(name, callback) {
|
|
23
|
-
if (this.services[name]) {
|
|
24
|
-
throw new Error(`Service with name '${name}' already exists.`)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
this.services[name] = callback
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get(name) {
|
|
31
|
-
if (!this.services[name]) {
|
|
32
|
-
throw new Error(`Service with name '${name}' does not exist.`)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const service = this.services[name]
|
|
36
|
-
|
|
37
|
-
if (service instanceof Function) {
|
|
38
|
-
return service.call(null, this)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return service
|
|
42
|
-
}
|
|
43
|
-
}
|