forked from didi/mpx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01586fc
commit d8b270d
Showing
7 changed files
with
137 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import VueCompositionAPI from '@vue/composition-api' | ||
import { LIFECYCLES_HOOKS, mergeWebHook } from './shim' | ||
|
||
function install(mpx) { | ||
if (__mpx_mode__ === 'web') { | ||
mpx.__vue.use(VueCompositionAPI) | ||
} else { | ||
// proxy 能力增强 | ||
mpx.__proxy.mixin = function (mixins) { | ||
mpx.mixin(mixins) | ||
} | ||
mpx.__proxy.observable = function (...args) { | ||
return mpx.observable(...args) | ||
} | ||
|
||
// web -> 小程序 LifeCycle | ||
const mpxProxyConfig = { | ||
optionMergeStrategies: {} | ||
} | ||
LIFECYCLES_HOOKS.forEach((hook) => { | ||
mpxProxyConfig.optionMergeStrategies[hook] = mergeWebHook | ||
}) | ||
mpx.__proxy.config = mpxProxyConfig | ||
|
||
const rawInstall = VueCompositionAPI.install | ||
VueCompositionAPI.install = function (proxy1, options, proxy2) { | ||
mpx.__proxy.version = '2.7.30' | ||
rawInstall(mpx.__proxy, options) | ||
} | ||
VueCompositionAPI.install(mpx) | ||
} | ||
} | ||
|
||
export default { | ||
install | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function dedupeHooks(hooks) { | ||
const res = [] | ||
for (let i = 0; i < hooks.length; i++) { | ||
if (res.indexOf(hooks[i]) === -1) { | ||
res.push(hooks[i]) | ||
} | ||
} | ||
return res | ||
} | ||
|
||
export function mergeWebHook(parentVal, childVal) { | ||
const res = childVal | ||
? parentVal | ||
? Array.isArray(parentVal) | ||
? parentVal.concat(childVal) | ||
: [parentVal, childVal] | ||
: Array.isArray(childVal) | ||
? childVal | ||
: [childVal] | ||
: parentVal | ||
return res ? dedupeHooks(res) : res | ||
} | ||
|
||
export const LIFECYCLES_HOOKS = [ | ||
'beforeMount', | ||
'mounted', | ||
'updated', | ||
'destroyed' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters