-
Notifications
You must be signed in to change notification settings - Fork 98
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: v2.0 #90
Merged
feat: v2.0 #90
Conversation
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
赞赞赞 |
Closed
好用,支持! |
2.0应该再推广推广吧,这么好用,感觉知道的人并不多,相关文章也很少 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
先前曾发过一个 RFC #37,也收到了很多社区朋友的反馈,不过由于年代有点久远了,这里把一些信息重新整理一下。
背景 & 动机
在 hox v1 中,我们的实现方案是在应用的 React 组件树之外,额外创建一个组件树,以存储 hox 中的 model。然而,这种方案渐渐显露出较多的弊端:
2.0 整体思路
如果要解决上面提到的这些问题,可以发现有一些方向是非常明确的:
下面来分别针对这两点展开介绍一下思路:
Context
如果完全基于 Context,那么大致思路就是 reto 了,所以当时 RFC 的评论区中很多朋友也在问:
createModel
这种直接创建全局状态的语法还是很好用的,如果全都是 Provider,在一些简单场景下会非常痛苦,为什么一定要废弃全局状态?所以在 2.0 的实现中,同时支持了创建全局状态
createGlobalStore
和创建局部状态createStore
,而且createGlobalStore
的用法、能力几乎和 v1 的createModel
是一模一样的。复用环境中已有的 React Renderer
如果不用
react-reconciler
自己封装一个 Custom Renderer,那就要复用业务中已有的 React Renderer,例如 React DOM,React Native,React DOM Server,这里的复用有两种思路:createGlobalStore(hook, ReactDOM.render)
HoxRoot
组件,让用户自己把这个组件渲染到页面上,这样 hox 就不需要关系怎么渲染自己了综合考虑之后,我选择了第 2 种方案,因为开发者的体验会更好一些,理解成本也比较低,还能直接复用已有的生态(例如 next.js)自动选择渲染环境。
具体用法和 API 介绍
见 README