Skip to content

Instantly share code, notes, and snippets.

@chodorowicz
Last active August 29, 2015 14:23
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 chodorowicz/558cf0eb3c80af1e3853 to your computer and use it in GitHub Desktop.
Save chodorowicz/558cf0eb3c80af1e3853 to your computer and use it in GitHub Desktop.
Get single item in Alt (Flux) + React
var React = require("react");
var ProductsStore = require('../../stores/ProductsStore');
function getState(id) {
var product = ProductsStore.getProduct(id);
return {
product: product
};
}
var CatalogDetail = React.createClass({
// mixins:[StoreWatchMixin(getCatalogItem)],
getInitialState: function() {
return getState(this);
}
}
var alt = require('../alt');
var ProductActions = require('../actions/ProductActions');
class ProductsStore {
constructor() {
this.products = require("./generator.js").products;
this.exportPublicMethods({
getProduct: this.getProduct.bind(this)
});
}
getProduct(id) {
id = parseInt(id, 10);
return _.find(this.products, function(product) {
return product.id === id;
});
}
}
module.exports = alt.createStore(ProductsStore, 'ProductsStore');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment