Skip to content

Instantly share code, notes, and snippets.

@deanius deanius/README.md
Last active Jan 10, 2019

Embed
What would you like to do?
const months = {0: "January", 1: "February", 2: "March", 3: "April", 4: "May", 5: "June", 6: "July",
7: "August", 8: "September", 9: "October", 10: "November", 11: "December"}
let download$ = fromEvent(document, "click", ".downloadable")
.map(e => months[e.target.attribues["data-month"]])
.map(month => ({
type: "download/start",
payload: { file: month + ".csv" }
}))
agent.on("download/start", ({ action }) => {
const { filename } = action.payload
return ajax({ url: "download.php?file=" + filename }).map(result => ({
filename,
bytes: result.response
}))
},
{ concurrency: "serial", type: "download/complete" })
agent.on("download/complete", ({ action }) => {
const { filename, bytes } = action.payload
localStorage.set(filename, bytes)
console.log("Saved " + filename)
})
agent.subscribe(download$)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.