-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathremotestorage-module.js
53 lines (42 loc) · 1.16 KB
/
remotestorage-module.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
var Todos = {
name: 'todos',
builder: function(privateClient) {
privateClient.declareType('todo', {
type: 'object',
properties: {
description: { type: 'string' },
done: { type: 'boolean' }
},
required: ['description']
});
return {
exports: {
init: function() {
privateClient.cache('');
},
on: privateClient.on,
async addTask (description) {
const url = Date.now().toString(36).toLowerCase();
const item = {
url,
description,
};
await privateClient.storeObject('todo', url, item);
return item;
},
async updateTask (url, done) {
// set `maxAge` to `false` to read from cache first
const item = await privateClient.getObject(url, false);
await privateClient.storeObject('todo', item.url, Object.assign(item, {
done,
}));
return item;
},
deleteTask: privateClient.remove.bind(privateClient),
listTasks: function() {
return privateClient.getAll('');
}
}
}
}
};