-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
70 lines (42 loc) · 895 Bytes
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// app component factory
var App = function(desire) {
var ui = desire('ui')
var version = desire('version')
return {
run: function() {
console.log('application version ' + version)
ui.show()
console.log('ui is visible')
}
}
}
// ui component factory
var UI = function(desire) {
return {
show: function() {
console.log('display ui')
}
}
}
// let's create a container
var Desire = require('./.')
var desire = new Desire()
// register it
desire.register({
app: App,
ui: UI,
version: Desire.value('1.0.0')
})
// now ask for the app component, and run
var app = desire('app')
app.run()
// some fake ui component
var FakeUI = function(desire) {
return {
show: function() {
console.log('this is a fake ui')
}
}
}
var app2 = App(new Desire({ ui: FakeUI, version: Desire.value('mock') }))
app2.run()