@mpxjs/store 2.8.14 → 2.8.23-alpha
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 +3 -3
- package/src/index.js +34 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/store",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.23-alpha",
|
|
4
4
|
"description": "A store for mpx framework",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "@types/index.d.ts",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/didi/mpx#readme",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@mpxjs/utils": "^2.8.
|
|
29
|
+
"@mpxjs/utils": "^2.8.23-alpha"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@mpxjs/core": "^2.8.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "3a6dff432fd46bab36a9866f92cffb6501e69909"
|
|
35
35
|
}
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import Mpx, { reactive, computed } from '@mpxjs/core'
|
|
2
|
+
import Vue from '../vue'
|
|
3
|
+
import createHummerPlugin from '../platform/builtInPlugins/hummerStorePlugin'
|
|
2
4
|
import {
|
|
3
5
|
getByPath,
|
|
4
6
|
warn,
|
|
@@ -118,6 +120,12 @@ class Store {
|
|
|
118
120
|
this.state = this.registerModule(options).state
|
|
119
121
|
this.resetStoreVM()
|
|
120
122
|
Object.assign(this, mapStore(this))
|
|
123
|
+
if (__mpx_mode__ === 'tenon') {
|
|
124
|
+
plugins.push(createHummerPlugin({
|
|
125
|
+
/* eslint-disable camelcase */
|
|
126
|
+
store_key: `MPX_STORE${options.__store_id}`
|
|
127
|
+
}))
|
|
128
|
+
}
|
|
121
129
|
plugins.forEach(plugin => plugin(this))
|
|
122
130
|
}
|
|
123
131
|
|
|
@@ -146,9 +154,9 @@ class Store {
|
|
|
146
154
|
|
|
147
155
|
registerModule (module) {
|
|
148
156
|
const state = module.state || {}
|
|
149
|
-
const reactiveModule =
|
|
150
|
-
state
|
|
151
|
-
|
|
157
|
+
const reactiveModule = __mpx_mode__ === 'tenon'
|
|
158
|
+
? Vue.reactive({ state })
|
|
159
|
+
: { state }
|
|
152
160
|
if (module.getters) {
|
|
153
161
|
reactiveModule.getters = transformGetters(module.getters, reactiveModule, this)
|
|
154
162
|
}
|
|
@@ -189,6 +197,16 @@ class Store {
|
|
|
189
197
|
const computedKeys = Object.keys(this.__wrappedGetters)
|
|
190
198
|
proxy(this.getters, vm, computedKeys)
|
|
191
199
|
proxy(this.getters, this.__depsGetters)
|
|
200
|
+
} else if (__mpx_mode__ === 'tenon') {
|
|
201
|
+
const computedObj = {}
|
|
202
|
+
Object.keys(this.__wrappedGetters).forEach(k => {
|
|
203
|
+
const getter = this.__wrappedGetters[k]
|
|
204
|
+
computedObj[k] = () => getter(this.state)
|
|
205
|
+
Object.defineProperty(this.getters, k, {
|
|
206
|
+
get: () => computedObj[k](),
|
|
207
|
+
enumerable: true // for local getters
|
|
208
|
+
})
|
|
209
|
+
})
|
|
192
210
|
} else {
|
|
193
211
|
reactive(this.state)
|
|
194
212
|
const computedObj = {}
|
|
@@ -199,6 +217,19 @@ class Store {
|
|
|
199
217
|
proxy(this.getters, this.__depsGetters)
|
|
200
218
|
}
|
|
201
219
|
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 替换state,tenon环境中使用
|
|
223
|
+
*/
|
|
224
|
+
replaceState (state) {
|
|
225
|
+
// todo 某些key可能无法删除
|
|
226
|
+
Object.assign(this.state, state)
|
|
227
|
+
// this.resetStoreVM()
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
_withCommit (fn) {
|
|
231
|
+
fn()
|
|
232
|
+
}
|
|
202
233
|
}
|
|
203
234
|
|
|
204
235
|
function genericSubscribe (fn, subs, options) {
|