-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjug.js
More file actions
68 lines (60 loc) · 1.6 KB
/
jug.js
File metadata and controls
68 lines (60 loc) · 1.6 KB
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
(function(mod) {
if (typeof exports == "object" && typeof module == "object") { // CommonJS
return mod(require.main.require("../lib/infer"), require.main.require("../lib/tern"));
}
if (typeof define == "function" && define.amd) // AMD
return define([ "tern/lib/infer", "tern/lib/tern" ], mod);
mod(tern, tern);
})(function(infer, tern) {
"use strict";
tern.registerPlugin("jug", function(server, options) {
return {
defs : defs
};
});
/**
* Return the id parameter of JUG.Factory.create method.
Ex : JUG.Factory.create('event') return 'event'
*/
function getParamId(argNodes) {
if (argNodes && argNodes[0] && argNodes[0].type == 'Literal') return argNodes[0].value;
}
infer.registerFunction("jug_create", function(_self, args, argNodes) {
var cx = infer.cx(), defs = cx.definitions["jug"];
var paramId = getParamId(argNodes);
switch(paramId) {
case 'talk':
return new infer.Obj(defs["Talk"].props.prototype);
case 'event':
return new infer.Obj(defs["Event"].props.prototype);
default:
return infer.ANull;
}
});
var defs = {
"!name": "jug",
"!define": {
"Talk": {
"!type": "fn(author: string, topic: string)",
"prototype": {
"author": "string",
"topic": "string"
}
},
"Event": {
"!type": "fn(name: string, when: +Date)",
"prototype": {
"name": "string",
"when" : "+Date"
}
}
},
"JUG": {
"Factory": {
"create" :{
"!type" : "fn(id: string) -> !custom:jug_create"
}
}
}
}
});