UNPKG

1.18 kBJavaScriptView Raw
1import Immutable, { Map, List } from 'immutable'
2
3import contextManager from './context'
4
5import * as common from './common'
6
7class reducer {
8 constructor(option) {
9 this.appInfo = option.appInfo
10 }
11
12 init = (state, option) => {
13 const {
14 data = {},
15 } = option
16
17 return this.initByImmutable(state, {
18 data: Immutable.fromJS(data),
19 })
20 }
21
22 initByImmutable = (state, option) => {
23 const {
24 data,
25 } = option
26
27 //清除state中非@@开头的属性,那属性是edf-app-loader增加的
28 const keys = []
29 state.mapKeys(key => {
30 if (key.indexOf('@@') === -1)
31 keys.push(key)
32 })
33
34 keys.forEach(key => {
35 state = state.remove(key)
36 })
37
38 //设置状态
39 return state
40 .set('data', data)
41 }
42
43 getMeta = common.getMeta
44
45 getField = common.getField
46
47 getFields = common.getFields
48
49 setField = common.setField
50
51 setFields = common.setFields
52
53 gm = common.getMeta
54
55 sm = common.setMetaForce
56
57 gf = common.getField
58
59 gfs = common.getFields
60
61 sf = common.setField
62
63 sfs = common.setFields
64
65 context = contextManager
66
67}
68
69export default function creator(option) {
70 return new reducer(option)
71}
\No newline at end of file