This repository has been archived by the owner on Jul 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.js
99 lines (76 loc) · 2.31 KB
/
demo.js
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
93
94
95
96
97
98
99
var io = require('socket.io')();
var State = require('ampersand-state');
var IOModel = require('./ampersand-io-model');
var client = require('socket.io-client');
var bar = io.of('/bar');
var foo = io.of('/foo');
io.on('connection', function(socket){
console.log('Test client connected!');
socket.on('model-create', function(data, cb){
console.log(data);
cb();
});
socket.on('model-update', function(data, cb){
console.log(data);
cb();
});
socket.on('model-fetch', function(data, cb){
console.log('about to emit');
socket.emit('fetch-response', {test: 'test'}, function(){console.log('done');});
console.log(data);
cb();
});
socket.on('model-remove', function(data, cb){
console.log(data);
cb();
});
});
io.listen(3000);
bar.on('connection', function(socket){
console.log('Test bar client connected!');
socket.on('model-fetch', function(data, cb){
console.log('about to emit bar');
socket.emit('fetch-response', {test: 'test'}, function(){console.log('done bar');});
console.log(data);
cb();
});
});
foo.on('connection', function(socket){
console.log('Test foo client connected!');
socket.on('model-fetch', function(data, cb){
console.log('about to emit foo');
socket.emit('fetch-response', {data: {id: 'fooModel', thread: 'test', source: 'test2', member: 'mymember'}}, function(){console.log('done foo');});
console.log(data);
cb();
});
});
var mymodelFoo = new (IOModel.extend({
props: {
id: ['string'],
thread: ['string'],
source: ['string'],
member: ['string']
}
}))({}, {socket: 'http://localhost:3000/foo'});
var mymodelBar = new (IOModel.extend({
props: {
id: ['string'],
thread: ['string'],
source: ['string'],
member: ['string']
}
}))({}, {socket: 'http://localhost:3000/bar'});
mymodelBar.save({id: 'barModel'});
mymodelBar.fetch({callback: function(){
console.log(mymodelBar.thread, mymodelBar.source);
}});
mymodelBar.destroy();
mymodelFoo.save({id: 'fooModel'});
mymodelFoo.fetch({callback: function(){
console.log(mymodelFoo.thread, mymodelFoo.source);
}});
mymodelFoo.destroy();
/*var barClient = client('http://localhost:3000/bar');
var fooClient = client('http://localhost:3000/foo');
barClient.emit('model-fetch', {test: 1}, function(){console.log('stuff');});
fooClient.emit('model-fetch', {test: 2}, function(){console.log('stuffCenas');});*/