Skip to content

Commit

Permalink
fix(mobx): 修复快应用下 store 未定义的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
nanjingboy authored and Chen-jj committed May 18, 2020
1 parent b3553c5 commit 3be1ff4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/taro-mobx-common/src/store.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
let store = {}
const appGlobal = global || {}
const globalRef = Object.getPrototypeOf(appGlobal) || appGlobal

export function getStore () {
if (process.env.TARO_ENV === 'alipay') {
return my.taroMobxStore || {}
} else if (process.env.TARO_ENV === 'quickapp') {
return globalRef.taroMobxStore || {}
}
return store
}

export function setStore (arg) {
if (process.env.TARO_ENV === 'alipay') {
my.taroMobxStore = arg
} else if (process.env.TARO_ENV === 'quickapp') {
globalRef.taroMobxStore = arg
} else {
store = arg
}
}
}

0 comments on commit 3be1ff4

Please sign in to comment.