@mpxjs/core 2.7.18 → 2.7.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.7.18",
3
+ "version": "2.7.25",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -41,5 +41,5 @@
41
41
  "url": "https://github.com/didi/mpx/issues"
42
42
  },
43
43
  "sideEffects": false,
44
- "gitHead": "5cca51d77d97143319c895dab301ef9a789ce40f"
44
+ "gitHead": "0bcd275c2d8a3fe33ba383b5c2b53e1988217f9e"
45
45
  }
@@ -9,23 +9,34 @@ function mapFactory (type, store) {
9
9
  return function (depPath, maps) {
10
10
  maps = normalizeMap(depPath, maps)
11
11
  const result = {}
12
- for (let key in maps) {
12
+ Object.entries(maps).forEach(([key, value]) => {
13
13
  result[key] = function (payload) {
14
- const value = maps[key]
15
- if (type === 'mutations') {
16
- return store.commit(value, payload)
17
- } else if (type === 'actions') {
18
- return store.dispatch(value, payload)
19
- } else {
20
- let getterVal = getByPath(store.getters, value, '', '__NOTFOUND__')
21
- if (getterVal === '__NOTFOUND__') {
22
- warn(`Unknown getter named [${value}].`)
23
- getterVal = ''
24
- }
25
- return getterVal
14
+ switch (type) {
15
+ case 'state':
16
+ if (typeof value === 'function') {
17
+ return value.call(this, store.state, store.getters)
18
+ } else {
19
+ let stateVal = getByPath(store.state, value, '', '__NOTFOUND__')
20
+ if (stateVal === '__NOTFOUND__') {
21
+ warn(`Unknown state named [${value}].`)
22
+ stateVal = ''
23
+ }
24
+ return stateVal
25
+ }
26
+ case 'getters':
27
+ let getterVal = getByPath(store.getters, value, '', '__NOTFOUND__')
28
+ if (getterVal === '__NOTFOUND__') {
29
+ warn(`Unknown getter named [${value}].`)
30
+ getterVal = ''
31
+ }
32
+ return getterVal
33
+ case 'mutations':
34
+ return store.commit(value, payload)
35
+ case 'actions':
36
+ return store.dispatch(value, payload)
26
37
  }
27
38
  }
28
- }
39
+ })
29
40
  return result
30
41
  }
31
42
  }
@@ -35,20 +46,6 @@ export default function (store) {
35
46
  mapGetters: mapFactory('getters', store),
36
47
  mapMutations: mapFactory('mutations', store),
37
48
  mapActions: mapFactory('actions', store),
38
- mapState: (depPath, maps) => {
39
- maps = normalizeMap(depPath, maps)
40
- const result = {}
41
- Object.keys(maps).forEach(key => {
42
- const value = maps[key]
43
- result[key] = function () {
44
- if (typeof value === 'function') {
45
- return value.call(this, store.state, store.getters)
46
- } else if (typeof value === 'string') {
47
- return getByPath(store.state, value)
48
- }
49
- }
50
- })
51
- return result
52
- }
49
+ mapState: mapFactory('state', store)
53
50
  }
54
51
  }