forked from andyet/thoonk.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeed.js
More file actions
92 lines (72 loc) · 2.46 KB
/
feed.js
File metadata and controls
92 lines (72 loc) · 2.46 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
var thoonkmodule = require('./thoonk');
var Feed = function(name, thoonk) {
thoonkmodule.ThoonkBaseObject.call(this, name, thoonk);
this.subscribables = ['publish', 'edit', 'retract'];
this.subinitted = false;
};
Feed.prototype = Object.create(thoonkmodule.ThoonkBaseObject.prototype);
Feed.prototype.constructor = Feed;
Feed.prototype.objtype = 'feed';
Feed.prototype.scriptdir = __dirname + '/scripts/feed';
(function() {
//continue extending the Feed prototype
this.handle_event = function(channel, msg) {
//overridden
var objsplit = channel.split(':');
var typesplit = objsplit[0].split('.');
var eventname = typesplit[2];
if(eventname == 'publish') {
var msgsplit = msg.split('\x00');
//pulish, id, item
this.emit('publish', msgsplit[0], msgsplit[1]);
this.emit('publishid:' + msgsplit[0], msgsplit[0], msgsplit[1]);
} else if (eventname == 'retract') {
this.emit('retract', msg);
}
};
this.create = function(config, callback) {
config = JSON.stringify(config);
return this.runscript('create', [config], callback);
};
this.config = function(config, callback) {
config = JSON.stringify(config);
return this.runscript('config', [config], callback);
};
this.publish = function(item, id, callback) {
if(id == undefined || id == null) {
id = uuid();
};
return this.runscript('publish', [id, item, Date.now().toString()], callback);
};
this.retract = function(id, callback) {
return this.runscript('retract', [id], callback);
};
this.get = function(id, callback) {
return this.runscript('get', [id], callback);
};
this.getIds = function(callback) {
return this.runscript('getids', [], callback);
};
this.getAll = function(callback) {
return this.runscript('getall', [], function(err, result) {
callback(err, JSON.parse(result));
});
};
this.length = function(callback) {
return this.runscript('length', [], callback);
};
this.hasId = function(id, callback) {
return this.runscript('hasid', [id], function(err, result) {
callback(err, Boolean(result));
});
};
}).call(Feed.prototype);
var Deck = function() {
};
Deck.prototype = (function() {
})();
var Job = function() {
};
Job.prototype = (function() {
})();
exports.Feed = Feed;