forked from aranm/scalable-javascript-architecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestModules.js
134 lines (104 loc) · 3.11 KB
/
TestModules.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
Core.register("Name-Module", function (sandbox) {
var ko = sandbox.getObservable();
var NameModel = function (first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);
this.fullName = ko.computed(function () {
// Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName.
return this.firstName() + " " + this.lastName();
}, this);
};
var nameModel;
return {
activate: function () {
nameModel = new NameModel("", "");
sandbox.bind(nameModel);
sandbox.addListener("Name", function (firstName, lastName) {
nameModel.firstName(firstName);
nameModel.lastName(lastName);
}, this);
},
destroy: function () {
}
};
});
Core.register("NextStudentButton-Module", function (sandbox) {
var NextButtonViewModel = function () {
this.next = function () {
sandbox.notify("GetNextName");
};
};
return {
activate: function () {
sandbox.bind(new NextButtonViewModel());
},
destroy: function () {
}
};
});
Core.register("Name-DataStore-Module", function (sandbox) {
var allNames = [
["Aran", "Mulholland"],
["Jim", "Taylor"],
["Bob", "Snoet"],
["Joe", "Hillman"]
];
var currentIndexer = -1;
return {
activate: function () {
//sandbox.notify("Name", allNames[currentIndexer][0], allNames[currentIndexer][1]);
sandbox.addListener("GetNextName", function () {
currentIndexer = currentIndexer + 1;
if (currentIndexer >= allNames.length) {
currentIndexer = 0;
}
sandbox.notify("Name", allNames[currentIndexer][0], allNames[currentIndexer][1]);
}, this);
sandbox.addListener("NamesLoaded", function (arrayOfNames) {
for (var i = 0, length = arrayOfNames.length; i < length; i++) {
allNames.push(arrayOfNames[i]);
}
}, this);
},
destroy: function () {
sandbox.removeAllListeners(this);
}
};
});
Core.register("Name-GetDataFromLibrary-Module", function (sandbox) {
return {
activate: function () {
//fire the ajax request
var data = {
id: 1
};
sandbox.request({
name: "getNames",
data: data,
success: function (response) {
sandbox.notify("NamesLoaded", response);
},
failure: function (response) {
}
});
},
destroy: function () {
sandbox.removeAllListeners(this);
}
};
});
Core.register("Error-Throwing-Module", function (sandbox) {
var viewModel = {
throwAnError: function () {
throw new Error("Im an Error");
}
};
return {
activate: function () {
sandbox.bind(viewModel);
},
destroy: function () {
sandbox.removeAllListeners(this);
}
};
});