-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
52 lines (41 loc) · 1.42 KB
/
index.html
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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>ElmTests</title>
<script type="text/javascript" src="elm.js"></script>
<script type="text/javascript" src="pouchdb-3.2.1.min.js"></script>
<script type="text/javascript" src="underscore-min.js"></script>
<!--link rel="stylesheet" href="style.css"-->
</head>
<body>
</body>
<script type="text/javascript">
var db = new PouchDB('elm-todo-state');
var remoteDb = new PouchDB('http://localhost:5984/elm-todo-state');
db.sync(remoteDb, {live: true});
var initialState;
var todomvc = Elm.fullscreen(Elm.Todo, { getState: {todos: [], field: "", uid: 0} });
db.get('storedState')
.then( function (state){ todomvc.ports.getState.send(state); })
.then( function(){
todomvc.ports.saveState.subscribe(function(signalState) {
db.get('storedState').then(function(storedState){
signalState._id = storedState._id;
signalState._rev = storedState._rev;
signalState.field = "";
storedState.field = "";
if (!_.isEqual(signalState, storedState)) {
db.put(signalState);
}
});
});
});
db.changes({live: true, include_docs: true, doc_ids: ['storedState']})
.on('change', function (change) {
var d = change.doc;
console.log("change");
todomvc.ports.getState.send({todos: d.todos, field: d.field, uid: d.uid });
});
</script>
</html>