UNPKG

qm-bus

Version:

千米公有云业务组件库

50 lines (44 loc) 1.23 kB
import { Action, Actor } from 'iflux2' import { fromJS } from 'immutable' import { isArray, contain } from '../../util/qm-array' export default class CategoryActor extends Actor { defaultState() { return { categories: [], expanded: [], selected: [], expandParent: true, } } @Action('initCategory') initCategory(state, value) { value = value.toJS ? value : fromJS(value) return state.set('categories', value).set( 'expanded', value.map(i => String(i.get('id'))) ) } @Action('initLeaves') initLeaves(state, value) { value = value.toJS ? value : fromJS(value) return state.set('leaves', value) } @Action('cate:expand') expand(state, expanded) { if (isArray(expanded)) { return state.set('expanded', fromJS(expanded)).set('expandParent', false) } else { let leaves = state.get('leaves').toArray() if (!contain(leaves, expanded)) { return state .update('expanded', expandeds => expandeds.concat(fromJS([expanded]))) .set('expandParent', true) } return state } } @Action('cate:select') select(state, selected) { return state.set('selected', fromJS(selected)) } }