Skip to content

Instantly share code, notes, and snippets.

@erichulburd
Created August 15, 2016 21:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erichulburd/28a874730a16f2fb91919217b5ec415b to your computer and use it in GitHub Desktop.
Save erichulburd/28a874730a16f2fb91919217b5ec415b to your computer and use it in GitHub Desktop.
Make sure to return Immutable objects in reducers
[ensureProducts]: (products_data, token)=>{
if (products_data === null){
return loop(
products_data,
Effects.promise(()=>{
let api = new ProductsApi(token);
return api.index()
.then(productsRetrieved)
})
)
}
return products_data;
},
// products_data from API response.
[productsRetrieved]: (_products_data, new_products_data)=>{
// return new_products_data <- not preferred. This is a plain JS object.
return Immutable.fromJS(new_products_data); // <- preferred
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment