connection.js
1.84 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
/******************************************************************************
* Connection implementation
* ***************************************************************************/
/**
* Defines a connection between two components
* @param source {object} component at the source
* @param signal {string} name of the signal emitting data
* @param destination {object} component at the destination
* @param slot {string} name of the signal receiving data
* @class
*/
ARCS.Connection = function (source, signal, destination, slot) {
/**
* Connects two components as described in this object
* @function ARCS.Connection#connect
*/
this.connect = function () {
try {
ARCS.Component.connect(source, signal, destination, slot);
} catch(e) { console.log(e, source, signal, destination, slot); }
};
/**
* Disconnects a signal/slot connection between the two components
* described in this object.
*/
this.disconnect = function () {
ARCS.Component.disconnect(source, signal, destination, slot);
};
this.getSource = function() {
return source;
};
this.getDestination = function () {
return destination;
};
this.getSlot = function () {
return slot;
};
this.getSignal = function () {
return signal;
};
};
/**
* Helper function that casts a connection from a description
* @param obj {object} a raw description of the connection
* @param context {object} the context in which this connection takes place.
* @return a connection
*/
ARCS.Connection.cast = function (obj, context) {
return new ARCS.Connection(context.getComponent(obj.source)/*[obj.source].instance*/, obj.signal,
context.getComponent(obj.destination)/*[obj.destination].instance*/, obj.slot);
};