@mpxjs/store 2.8.15 → 2.8.23-alpha.2

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.15",
3
+ "version": "2.8.23-alpha.2",
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.15"
29
+ "@mpxjs/utils": "^2.8.23-alpha"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "@mpxjs/core": "^2.8.0"
33
33
  },
34
- "gitHead": "292c54cd571b1cdc3ca7cf9ffa8ab13ed2da6158"
34
+ "gitHead": "556f754c8b43cb825a8d5d5040b1cdf7a6fdd613"
35
35
  }
@@ -0,0 +1 @@
1
+ export default () => () => {} // mock plugin in other mode
@@ -0,0 +1,3 @@
1
+ import { createHummerPlugin } from '@hummer/tenon-store'
2
+
3
+ export default createHummerPlugin
package/src/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import Mpx, { reactive, computed } from '@mpxjs/core'
2
+ import createHummerPlugin from './builtInPlugins/hummerStorePlugin'
2
3
  import {
3
4
  getByPath,
4
5
  warn,
@@ -118,6 +119,12 @@ class Store {
118
119
  this.state = this.registerModule(options).state
119
120
  this.resetStoreVM()
120
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
+ }
121
128
  plugins.forEach(plugin => plugin(this))
122
129
  }
123
130
 
@@ -146,9 +153,9 @@ class Store {
146
153
 
147
154
  registerModule (module) {
148
155
  const state = module.state || {}
149
- const reactiveModule = {
150
- state
151
- }
156
+ const reactiveModule = __mpx_mode__ === 'tenon'
157
+ ? Mpx.__vue.reactive({ state })
158
+ : { state }
152
159
  if (module.getters) {
153
160
  reactiveModule.getters = transformGetters(module.getters, reactiveModule, this)
154
161
  }
@@ -189,6 +196,16 @@ class Store {
189
196
  const computedKeys = Object.keys(this.__wrappedGetters)
190
197
  proxy(this.getters, vm, computedKeys)
191
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
207
+ })
208
+ })
192
209
  } else {
193
210
  reactive(this.state)
194
211
  const computedObj = {}
@@ -199,6 +216,19 @@ class Store {
199
216
  proxy(this.getters, this.__depsGetters)
200
217
  }
201
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()
231
+ }
202
232
  }
203
233
 
204
234
  function genericSubscribe (fn, subs, options) {