package react.store; import react.ReactComponent; import react.ReactMacro.jsx; import Common; using Lambda; typedef ProductListProps = { var categories:Array; var productsBySubcategoryIdMap:Map>; var filters:Array; var addToCart:ProductInfo -> Int -> Void; }; class ProductList extends react.ReactComponentOfProps { override public function render(){ return jsx('
${renderCategories()}
'); } function renderCategories() { return props.categories.map(function(category) { if (!props.filters.has(category.name)) return null; return jsx('

${category.name}

${renderSubCategories(category)}
'); }); } function renderSubCategories(category) { var subCategories = category.subcategories.map(function(category) { if (!props.productsBySubcategoryIdMap.exists(category.id)) return jsx('
Loading...
'); var products = props.productsBySubcategoryIdMap.get(category.id); return jsx('

${category.name}

${renderProducts(products)}
'); }); return jsx('
$subCategories
'); } function renderProducts(products) { return products.map(function(product) { return jsx(' '); }); } }