Skip to content

Commit

Permalink
feat: update review
Browse files Browse the repository at this point in the history
  • Loading branch information
wangshunnn committed Jan 21, 2025
1 parent 15db45d commit 415920d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 1 addition & 3 deletions packages/core/src/core/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ export default class MpxProxy {
// web中BEFORECREATE钩子通过vue的beforeCreate钩子单独驱动
this.callHook(BEFORECREATE)
setCurrentInstance(this)
if (isReact) {
this.parentProvides = this.options.parentProvides
} else {
if (!isReact) {
this.parent = this.resolveParent()
this.provides = this.parent ? this.parent.provides : Object.create(null)
}
Expand Down
9 changes: 5 additions & 4 deletions packages/core/src/platform/patch/getDefaultOptions.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ const instanceProto = {
}
}

function createInstance ({ propsRef, type, rawOptions, currentInject, validProps, components, pageId, intersectionCtx, relation }) {
function createInstance ({ propsRef, type, rawOptions, currentInject, validProps, components, pageId, intersectionCtx, relation, parentProvides }) {
const instance = Object.create(instanceProto, {
dataset: {
get () {
Expand Down Expand Up @@ -282,6 +282,8 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps
}

const proxy = instance.__mpxProxy = new MpxProxy(rawOptions, instance)
// 在 created 之前设置 parentProvides
proxy.parentProvides = parentProvides
proxy.created()

Object.assign(proxy, {
Expand Down Expand Up @@ -446,8 +448,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
let isFirst = false
if (!instanceRef.current) {
isFirst = true
rawOptions.parentProvides = parentProvides
instanceRef.current = createInstance({ propsRef, type, rawOptions, currentInject, validProps, components, pageId, intersectionCtx, relation })
instanceRef.current = createInstance({ propsRef, type, rawOptions, currentInject, validProps, components, pageId, intersectionCtx, relation, parentProvides })
}
const instance = instanceRef.current
useImperativeHandle(ref, () => {
Expand Down Expand Up @@ -541,7 +542,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
root = cloneElement(root, rootProps)
}

const provides = useMemo(() => proxy.provides, [proxy.provides])
const provides = proxy.provides
if (provides) {
root = createElement(ProviderContext.Provider, { value: provides }, root)
}
Expand Down

0 comments on commit 415920d

Please sign in to comment.