Created
February 29, 2016 17:58
-
-
Save bendrucker/f1cfe4ab13294e4a0543 to your computer and use it in GitHub Desktop.
Async component transitions
This file contains 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
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