Fix some localForage stuff

This commit is contained in:
Richard Feldman
2018-08-12 14:36:05 -04:00
parent fc4a70fc28
commit 8dfa9f70b7
4 changed files with 2823 additions and 28 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -4,39 +4,39 @@
<meta charset="utf-8">
<title>Elm Workshop</title>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<!-- Favicon -->
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">
<meta name="msapplication-TileColor" content="#da532c">
<meta name="theme-color" content="#ffffff">
<!-- Import Ionicon icons & Google Fonts our Bootstrap theme relies on -->
<link href="//code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css" rel="stylesheet" type="text/css">
<link href="/fonts.css" rel="stylesheet" type="text/css">
<!-- Import the custom Bootstrap 4 theme from our hosted CDN -->
<link rel="stylesheet" href="/main.css">
<script src="/elm.js"></script>
<!-- We'll use localForage as a JavaScript interop example in part9! -->
<script src="/assets/localForage.js"></script>
<script src="elm.js"></script>
</head>
<body>
<script>
var app = Elm.Main.init({flags: localStorage.session || null});
// 👋 Hi there!
//
// If you're working on the JS interop exercise for part9,
// all the info you need on the JS side is in this <script> right here.
//
// On the Elm side, you'll need to make changes to `part9/src/Session.elm`.
localforage.getItem("session", function(err, session) {
var app = Elm.Main.init({flags: session});
app.ports.storeSession.subscribe(function(session) {
localStorage.session = session;
// Report that the new session was stored succesfully.
setTimeout(function() { app.ports.onSessionChange.send(session); }, 0);
app.ports.storeSession.subscribe(function(newErr, newSession) {
localforage.setItem("session", newSession, function() {
app.ports.onSessionChange.send(newSession);
});
});
});
window.addEventListener("storage", function(event) {
if (event.storageArea === localStorage && event.key === "session") {
app.ports.onSessionChange.send(event.newValue);
}
}, false);
</script>
</body>
</html>