-
Notifications
You must be signed in to change notification settings - Fork 381
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
[feat]rn-relatons #1679
base: master
Are you sure you want to change the base?
[feat]rn-relatons #1679
Conversation
const root = rawOptions.options?.disableMemo ? proxy.effect.run() : useMemo(() => proxy.effect.run(), [proxy.stateVersion]) | ||
const runRenderEffect = () => { | ||
if (needRelationContext(rawOptions)) { | ||
return createElement(RelationsContext.Provider, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接包在root上就可以了吧
@@ -117,6 +118,7 @@ global.currentInject.firstPage = ${JSON.stringify(firstPage)}\n` | |||
content += `global.currentInject.getComponents = function () { | |||
return ${shallowStringify(componentsMap)} | |||
}\n` | |||
content += `global.currentInject.componentPath = '/' + ${JSON.stringify(outputPath)}\n` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
页面是不是不用注入
}) | ||
} | ||
|
||
const RelationsContext = createContext(null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context可以以outputPath为key存一系列
if (item.type?.__mpxBuiltIn) { // 如果是基础节点,继续向下查找 | ||
return isChildNode(item, instance) | ||
} else { | ||
return item.type === instance.__getReactFunctionComponent() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
光凭这个ctor也没办法判断当前的instance一定是child吧
4ded781
to
4418593
Compare
@@ -0,0 +1,2 @@ | |||
import relationsMixin from './relationsMixin.ios' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
现在不需要加这个额外的.android了,文件条件编译找不到.android会自动去找.ios
@@ -233,6 +233,18 @@ function createInstance ({ propsRef, type, rawOptions, currentInject, validProps | |||
}, | |||
enumerable: false | |||
}, | |||
__componentPath: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里也限定组件再挂载吧,否则会取到其他组件的值很奇怪
@@ -374,6 +386,43 @@ function usePageStatus (navigation, pageId) { | |||
}, [navigation]) | |||
} | |||
|
|||
const RelationsContext = createContext(null) | |||
|
|||
const needRelationContext = (options) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
relations的分析可以createComponent里做完直接存在闭包里,没有必要在render里做
@@ -384,11 +433,12 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) { | |||
const propsRef = useRef(null) | |||
const intersectionCtx = useContext(IntersectionObserverContext) | |||
const pageId = useContext(RouteContext) | |||
const relation = useContext(RelationsContext) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
解析放到mount中进行,render中简单透传relation即可
if (relationMap[path]) { | ||
const target = relationMap[path] | ||
const targetRelation = target.__mpxProxy.options.relations?.[this.__componentPath] | ||
if (targetRelation && targetRelation.type === relationTypeMap[type] && target.__componentPath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target.__componentPath 这个判断为啥需要
getRelationNodes (path) { | ||
return this.__mpxRelationNodesMap[path] || null | ||
}, | ||
__mpxCollectRelations () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感觉这个循环还有this.__mpxRelations有点多余,如果下面的this.__relation是按需生成的这里可以省略很多逻辑
if (!relation[componentPath]) { | ||
relation[componentPath] = instance | ||
} | ||
return relation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要返回一个新对象,而不是修改原有对象
if (rawOptions.methods) rawOptions.methods = wrapMethodsWithErrorHandling(rawOptions.methods) | ||
const defaultOptions = memo(forwardRef((props, ref) => { | ||
const instanceRef = useRef(null) | ||
const propsRef = useRef(null) | ||
const intersectionCtx = useContext(IntersectionObserverContext) | ||
const pageId = useContext(RouteContext) | ||
const relation = useContext(RelationsContext) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(hasDescendantRelation || hasAncestorRelation) {
relation = useContext(RelationsContext)
}
const collectRelations = (ancestorRelations, relationMap, componentPath = '') => { | ||
const relations = {} | ||
const relationNodesMap = {} | ||
Object.keys(ancestorRelations).forEach(path => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个遍历还是放在mounted时执行吧,可以和exec('linked')用一个循环
No description provided.