import immer from 'immer' ; import { Modeler } from 'redux-aggregate' ; import { TodosST , TodosQR , TodosMT , TodosModel } from './todos' ; import { TodoST } from './todo' ; export interface TodosPresentST extends TodosST { showAll : boolean ; } export const TodosPresentModel = injects => ( { ... TodosModel ( ) , showAll : true , ... injects } ) ; function getDoingItems ( state ) { return state . items . filter ( item => ! item . done ) ; } function getDoneItems ( state ) { return state . items . filter ( item => item . done ) ; } function getVisibleItems ( state ) { return state . showAll ? state . items : getDoingItems ( state ) ; } function getTodosCountStatusLabel ( state ) { const all = `all: ${ state . items . length }` ; const doing = `doing: ${ getDoingItems ( state ) . length }` ; const done = `done: ${ getDoneItems ( state ) . length }` ; return `${ all } / ${ doing } / ${ done }` ; } function getToggleVisibleItemsBtnLabel ( state ) { return state . showAll ? 'hide done items' : 'show all items' ; } export const TodosPresentQR = { ... TodosQR , getVisibleItems , getTodosCountStatusLabel , getToggleVisibleItemsBtnLabel } ; const toggleShowAll = ( state ) : TodosPresentST => immer ( state , _state => { _state . showAll = ! _state . showAll ; } ) ; export const TodosPresentMT = { ... TodosMT , toggleShowAll } ;