forked from bryanjenningz/25-elm-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path25-navigation-todos.html
36 lines (33 loc) · 923 Bytes
/
25-navigation-todos.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
<!-- TODO: UPGRADE THIS FILE TO ELM 0.19 -->
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.css">
</head>
<body>
<script src="elm.js"></script>
<script>
var isTodos = function(todos) {
return Array.isArray(todos) && todos.every(function(todo) {
return (
!!todo &&
typeof todo.id === 'number' &&
typeof todo.text === 'string' &&
typeof todo.completed === 'boolean'
);
});
};
var todosDefault = function(todos) {
return isTodos(todos) ? todos : [];
};
var app = Elm.Main.init({
flags : {
todos: todosDefault(JSON.parse(localStorage.todos || '[]'))
}
});
app.ports.saveTodos.subscribe(function(todos) {
localStorage.todos = JSON.stringify(todos);
});
</script>
</body>
</html>