Concepts

View-model selector

Try the free JavaScript compiler

Derive a presentation-oriented result from canonical state and explicit criteria.

Formal Syntax & Structure

javascript syntaxjavascript
selectView(state, criteria) → viewModel

Working Example

Example Snippetjavascript
(async () => {const state={items:[{id:"A",qty:2},{id:"B",qty:0},{id:"C",qty:4}]};const select=s=>({visible:s.items.filter(x=>x.qty>0).map(x=>x.id),total:s.items.reduce((n,x)=>n+x.qty,0)});console.log(JSON.stringify(select(state)));})()
JavaScript Reference