Skip to content

Instantly share code, notes, and snippets.

@simenbrekken
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save simenbrekken/87f78f8dfd44f0b6bd63 to your computer and use it in GitHub Desktop.

Select an option

Save simenbrekken/87f78f8dfd44f0b6bd63 to your computer and use it in GitHub Desktop.
Flux Server Initialization
var categories = new Promise(function(resolve, reject) {
var onChange = function() {
CategoryStore.removeChangeListener('change', onChange)
resolve(CategoryStore.getAll())
}
CategoryStore.addChangeListener('change', onChange)
CategoryActions.loadAll()
})
var products = new Promise(function(resolve, reject) {
categories.then(function() {
var category = CategoryStore.get(params.categoryId)
var onChange = function() {
ProductStore.removeChangeListener('change', onChange)
resolve(ProductStore.getAllForCurrentCategory())
}
ProductStore.addChangeListener('change', onChange)
ProductActions.loadCategory(category.id)
})
})
Promise.props({
categories: categories,
products: products
}).then(function(data) {
res.render('index', {data: data})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment