-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (35 loc) · 1009 Bytes
/
server.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
let RibServer = require('rib-server').default;
let todos= [];
let todoNum = 0;
let myRib = new RibServer();
let myRibClient;
RibServer.setRoute('/', __dirname+'/client/index.html');
RibServer.setClientFolder(__dirname+'/client');
myRib.onConnect((client) => {
myRibClient = client;
});
function getTodos(){
return todos;
}
function addTodo(todo) {
todo.id = todoNum++;
todos.push(todo);
myRibClient.appendTodo(todo);
}
addTodo.argTypes = ['object'];
function deleteTodo(id){
for(let i=0;i<todos.length;i++){
if(todos[i].id==id) todos.splice(i,1);
}
myRibClient.removeTodo(id);
}
deleteTodo.argTypes = ['number'];
function doneTodo(id){
for(let i=0;i<todos.length;i++){
if(todos[i].id==id) todos[i].done = true;
}
console.log(todos);
}
doneTodo.argTypes = ['number'];
myRib.exposeFunctions([addTodo, getTodos, deleteTodo, doneTodo]);
RibServer.startServer(5000, 'This is much easier to program');