-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocs.js
60 lines (44 loc) · 1.29 KB
/
docs.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
DocsPackage = {};
DocsPackage.addDocTree = function(docTree) {
_docTree.set(_.deepExtendWithoutArrays(_docTree.get(), docTree));
}
DocsPackage.addDocNames = function(docNames) {
_docNames.set(_.uniq(_docNames.get().concat(docNames)));
}
DocsPackage.getDocTree = function() {
return _docTree.get();
}
DocsPackage.getDocNames = function() {
return _docNames.get();
}
if (Meteor.isClient) {
// Define local variables
var _docTree = new ReactiveVar({})
, _docNames = new ReactiveVar([]);
// Fetch server documentation
Meteor.call('DocsPackageGetServerDocs', function(err, data) {
if (err) throw err;
DocsPackage.addDocNames(data.docNames);
DocsPackage.addDocTree(data.docTree);
});
}
if (Meteor.isServer) {
// Simulate reactive-var interface
var NonreactiveVar = function(initialValue) {
var value = initialValue;
this.get = function() { return value; };
this.set = function(v) { value = v; return this; };
}
// Define local variables
var _docTree = new NonreactiveVar({})
, _docNames = new NonreactiveVar([]);
// Serve server documentation to client
Meteor.methods({
'DocsPackageGetServerDocs': function() {
return {
docNames: DocsPackage.getDocNames(),
docTree: DocsPackage.getDocTree()
}
}
});
}