Last active
April 9, 2018 21:07
-
-
Save arsduo/58cd6d6e2f0e4b31e4541413ae1e8de8 to your computer and use it in GitHub Desktop.
Examples for the ElmRings Blog Post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
handleHistoryExport(event) { | |
const target = event.target; | |
// see if we're downloading data from Elm 0.18.x | |
// assuming that the history export format won't change in a patch version 🤞 | |
if (target.href && unescape(target.href).match(/{"elm":0.18/)) { | |
// Elm delivers the data in the format | |
// 'data:' + mime + ',' + encodeURIComponent(jsonString)); | |
const historyData = unescape(target.href.split(/,/)[1]); | |
// you'll generally want to handle this data in Javascript, since nothing good would likely come from | |
// putting an export of the Elm history back into the Elm history | |
processHistoryData(historyData); | |
// when triggered automatically, we don't want to harass the user with an unexpected download prompt | |
// you may further want this to be always disabled, up to you | |
if (!this.allowDownload) { | |
event.preventDefault(); | |
} | |
return this.allowDownload; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment