Skip to content

Instantly share code, notes, and snippets.

@danderson00
Created June 14, 2017 19:00
Show Gist options
  • Save danderson00/cf87e5e7d12254cb223a3f5167244b26 to your computer and use it in GitHub Desktop.
Save danderson00/cf87e5e7d12254cb223a3f5167244b26 to your computer and use it in GitHub Desktop.
import api from 'webpack-worker/api'
// initialization arguments can be passed from the client
api(url => {
// perform any async initialization required by returning a promise
fetch(url)
.then(response => response.text())
.then(text => {
var data = parseFile(text)
// at the end of the promise chain, return the api we want to expose
return {
topTenMovers: filter => {
var filteredData = filterData(data, filter)
var stocks = aggregateStocks(filteredData)
var topTen = findTopTen(stocks)
return mapToVectors(topTen)
},
// add other API functions here
}
})
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment