Skip to content

Instantly share code, notes, and snippets.

@bendrucker
Created February 29, 2016 17:58
Show Gist options
  • Save bendrucker/f1cfe4ab13294e4a0543 to your computer and use it in GitHub Desktop.
Save bendrucker/f1cfe4ab13294e4a0543 to your computer and use it in GitHub Desktop.
Async component transitions
Depots.load = function load (state, callback) {
xhr('...', function (err, data) {
if (err) return callback(err)
state[arrayKey].set(data)
callback(null, data)
})
}
// app.js
Depots.load(state.depots, function (err, data) {
if (err) return console.error(err)
console.log('data', data)
})
var steps = [{
component: Depots,
key: 'depots'
}]
var Component = steps[index].component
var load = Component.load || noopLoad
if (typeof Component.load === 'function') {
state.loading.set(true)
Component.load(state[key], function () {
state.loading.set(false)
})
}
function noopLoad (state, callback) {
callback(null)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment