-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
35 lines (31 loc) · 1.02 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
<!DOCTYPE html>
<html>
<head>
<link rel="favicon" type="image/ico" href="logo.ico" />
<meta charset="utf-8">
<title>PsyApp</title>
<script src="elm.js"></script>
</head>
<body>
<script>
var storageKey = "store";
var flags = localStorage.getItem(storageKey);
var app = Elm.Main.init({flags: flags});
app.ports.storeCache.subscribe(function(val) {
if (val === null) {
localStorage.removeItem(storageKey);
} else {
localStorage.setItem(storageKey, JSON.stringify(val));
}
// Report that the new session was stored successfully.
setTimeout(function() { app.ports.onStoreChange.send(val); }, 0);
});
// Whenever localStorage changes in another tab, report it if necessary.
window.addEventListener("storage", function(event) {
if (event.storageArea === localStorage && event.key === storageKey) {
app.ports.onStoreChange.send(event.newValue);
}
}, false);
</script>
</body>
</html>