Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mobx):修复快应用下 store 未定义及页面不刷新问题(#4248) #6367

Merged
merged 2 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/taro-cli/src/util/resolve_npm_files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,16 @@ export function npmCodeHack (filePath: string, content: string, buildAdapter: BU
const basename = path.basename(filePath)
switch (basename) {
case 'mobx.js':
// 解决支付宝小程序全局window或global不存在的问题
// 解决支付宝和快应用 global 问题
let globalContent
if (process.env.TARO_ENV === 'quickapp') {
globalContent = 'global.__proto__'
} else {
globalContent = 'typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {}'
}
content = content.replace(
/typeof window\s{0,}!==\s{0,}['"]undefined['"]\s{0,}\?\s{0,}window\s{0,}:\s{0,}global/,
'typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : {}'
globalContent
)
break
case '_html.js':
Expand Down
6 changes: 5 additions & 1 deletion packages/taro-mobx-common/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ let store = {}
export function getStore () {
if (process.env.TARO_ENV === 'alipay') {
return my.taroMobxStore || {}
} else if (process.env.TARO_ENV === 'quickapp') {
return global.__proto__.taroMobxStore || {}
}
return store
}

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