invocation.js
1.99 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
/******************************************************************************
* Invocation implementation
* ***************************************************************************/
/**
* Defines an invocation
* @param destination {object} component on which to perform invocation
* @param slot {string} name of the slot
* @param value {mixed} value passed to the invoked slot
* @constructor
*/
ARCS.Invocation = function (destination, slot, value) {
this.getDestination = function () {
return destination;
};
this.getSlot = function () {
return slot;
};
this.getValue = function () {
return value;
};
this.invoke = function () {
var func = destination[slot];
if (func === undefined) {
console.error("Undefined slot %s of component %s", slot, destination);
return;
}
func.apply(destination, value);
};
};
/**
* Helper function that casts an invocation from a description
* @param obj {object} a raw description of the invocation
* @param context {object} the context in which this invocation takes place.
* @return an invocation
*/
ARCS.Invocation.cast = function (obj, context) {
if (obj.value !== undefined) {
var component = context.getComponent(obj.destination);
if (component === undefined) {
console.error("[ARCS] Destination ",obj.destination, " is undefined");
}
return new ARCS.Invocation(component, obj.slot, obj.value);
}
// this one looks odd, seems there is a failure in the logic.
if (obj.ref !== undefined) {
return new ARCS.Invocation(context.getComponent(obj.destination), obj.slot, context.getConstant(obj.ref));
}
};
/*ARCS.Invocation.revert = function(obj, context) {
return {
destination: context
};
};*/
ARCS.Invocation.PRE_CONNECTION = 0;
ARCS.Invocation.POST_CONNECTION = 1;
ARCS.Invocation.CLEAN_UP = 2;