blob: 6c9bf08f35c2501e7064b0b5638a5965280f619c (
plain)
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
|
// Enyo interface for Sugar
enyo.Sugar = {};
enyo.Sugar.component = null;
enyo.Sugar.sendMessage = function(name, args) {
if (enyo.Sugar.component) {
enyo.Sugar.component.signal(name, JSON.parse(args));
}
};
enyo.kind({
name: "Sugar",
// Constructor, init component
create: function() {
this.inherited(arguments);
this.handlers = [];
enyo.Sugar.component = this;
},
// Connect a callback to a message
connect: function(name, callback) {
this.handlers[name] = callback;
},
// Send a message to Sugar
sendMessage: function(name, args) {
var msg = "";
msg = msg + "enyo://"+name.length+"/"+name;
if (!args)
msg = msg + "/0/";
else {
var value = JSON.stringify(args);
msg = msg + "/"+value.length+"/"+value;
}
console.log(msg);
},
// A message was sent by Sugar
signal: function(name, args) {
var callback = this.handlers[name];
if (callback) {
callback(args);
}
}
});
|