@mpxjs/store 2.8.23-alpha.2 → 2.8.40-test
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/store",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.40-test",
|
|
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.40-test"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"@mpxjs/core": "^2.8.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "8524f9b69ebcfb0667ebff2608cf6f675f14f141"
|
|
35
35
|
}
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import Mpx, { reactive, computed } from '@mpxjs/core'
|
|
2
|
-
import createHummerPlugin from './builtInPlugins/hummerStorePlugin'
|
|
1
|
+
import Mpx, { reactive, computed, effectScope } from '@mpxjs/core'
|
|
3
2
|
import {
|
|
4
3
|
getByPath,
|
|
5
4
|
warn,
|
|
@@ -116,15 +115,10 @@ class Store {
|
|
|
116
115
|
this.mutations = {}
|
|
117
116
|
this.actions = {}
|
|
118
117
|
this._subscribers = []
|
|
118
|
+
this._scope = effectScope(true)
|
|
119
119
|
this.state = this.registerModule(options).state
|
|
120
120
|
this.resetStoreVM()
|
|
121
121
|
Object.assign(this, mapStore(this))
|
|
122
|
-
if (__mpx_mode__ === 'tenon') {
|
|
123
|
-
plugins.push(createHummerPlugin({
|
|
124
|
-
/* eslint-disable camelcase */
|
|
125
|
-
store_key: `MPX_STORE${options.__store_id}`
|
|
126
|
-
}))
|
|
127
|
-
}
|
|
128
122
|
plugins.forEach(plugin => plugin(this))
|
|
129
123
|
}
|
|
130
124
|
|
|
@@ -153,9 +147,9 @@ class Store {
|
|
|
153
147
|
|
|
154
148
|
registerModule (module) {
|
|
155
149
|
const state = module.state || {}
|
|
156
|
-
const reactiveModule =
|
|
157
|
-
|
|
158
|
-
|
|
150
|
+
const reactiveModule = {
|
|
151
|
+
state
|
|
152
|
+
}
|
|
159
153
|
if (module.getters) {
|
|
160
154
|
reactiveModule.getters = transformGetters(module.getters, reactiveModule, this)
|
|
161
155
|
}
|
|
@@ -185,49 +179,28 @@ class Store {
|
|
|
185
179
|
}
|
|
186
180
|
|
|
187
181
|
resetStoreVM () {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const computedKeys = Object.keys(this.__wrappedGetters)
|
|
197
|
-
proxy(this.getters, vm, computedKeys)
|
|
198
|
-
proxy(this.getters, this.__depsGetters)
|
|
199
|
-
} else if (__mpx_mode__ === 'tenon') {
|
|
200
|
-
const computedObj = {}
|
|
201
|
-
Object.keys(this.__wrappedGetters).forEach(k => {
|
|
202
|
-
const getter = this.__wrappedGetters[k]
|
|
203
|
-
computedObj[k] = () => getter(this.state)
|
|
204
|
-
Object.defineProperty(this.getters, k, {
|
|
205
|
-
get: () => computedObj[k](),
|
|
206
|
-
enumerable: true // for local getters
|
|
182
|
+
this._scope.run(() => {
|
|
183
|
+
if (__mpx_mode__ === 'web') {
|
|
184
|
+
const Vue = Mpx.__vue
|
|
185
|
+
const vm = new Vue({
|
|
186
|
+
data: {
|
|
187
|
+
__mpxState: this.state
|
|
188
|
+
},
|
|
189
|
+
computed: this.__wrappedGetters
|
|
207
190
|
})
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
computedObj
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
* 替换state,tenon环境中使用
|
|
222
|
-
*/
|
|
223
|
-
replaceState (state) {
|
|
224
|
-
// todo 某些key可能无法删除
|
|
225
|
-
Object.assign(this.state, state)
|
|
226
|
-
// this.resetStoreVM()
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
_withCommit (fn) {
|
|
230
|
-
fn()
|
|
191
|
+
const computedKeys = Object.keys(this.__wrappedGetters)
|
|
192
|
+
proxy(this.getters, vm, computedKeys)
|
|
193
|
+
proxy(this.getters, this.__depsGetters)
|
|
194
|
+
} else {
|
|
195
|
+
reactive(this.state)
|
|
196
|
+
const computedObj = {}
|
|
197
|
+
Object.entries(this.__wrappedGetters).forEach(([key, value]) => {
|
|
198
|
+
computedObj[key] = computed(value)
|
|
199
|
+
})
|
|
200
|
+
proxy(this.getters, computedObj)
|
|
201
|
+
proxy(this.getters, this.__depsGetters)
|
|
202
|
+
}
|
|
203
|
+
})
|
|
231
204
|
}
|
|
232
205
|
}
|
|
233
206
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default () => () => {} // mock plugin in other mode
|