Comments (8)
@ninesunsabiu 嵌套式隔离是指什么形式?部分 domain 来自内层,部分 domain 来自外层?
对于这种场景,可以通过添加指定的 scope key
到 domain arg
里,也就是说在内层使用的是 MyDomain({ scope: 'inner', ...others })
,而外层使用的是 MyDomain({ scope: 'outer' , ...others})
。这样两个 domain 分别是不同的实例。
通过参数化 domain 去管理多实例,用参数设计来管理 scope 问题。这个策略更加灵活,因为它们仍在同一个 store 里,可以互相通讯(domain.getDomain)和组合。
from remesh.
from remesh.
Thank feedback. We will check it later:-)
from remesh.
@wqy8593521 有很多种方法,要看具体你的场景。
- 分别使用
<RemeshRoot />
把两个区域间隔开,就得到了两个独立的RemeshStore
了。其中,它们内部的所有 domain 实例都是互不影响的 - 使用带参数的
RemeshDomain(arg)
,如MyDomain('id1')
和MyDomain('id2')
对应的是两个不同的domain
实例。
from remesh.
@wqy8593521 有很多种方法,要看具体你的场景。
- 分别使用
<RemeshRoot />
把两个区域间隔开,就得到了两个独立的RemeshStore
了。其中,它们内部的所有 domain 实例都是互不影响的
如果是兄弟层级的需要隔离开,用两个 <RemeshRoot />
可以,如果想要嵌套形式的隔离的话,内层的会遮蔽祖先层级。
是否考虑像 react-redux
那样,可以自定持有 store
的 ReactContext
并且能有 createUseRemeshXXX(Context)
这样二次创造 Hook 的能力?
from remesh.
嵌套式隔离是指什么形式?部分 domain 来自内层,部分 domain 来自外层?
嵌套形式具体是指
<RemeshRoot store={storeOuter}>
... scope A
<NestComponent>
<RemeshRoot store={storeInner}>
... scope B
</RemeshRoot>
</NestComponent>
</RemeshRoot>
之所以会顺便提出这个想法是因为在我们产品中正在经历一场 单一 store 到 多 store 的 redux store
重构。产品项目里之前的单一 store 持续膨胀,create-store
引入了非常多的模块,因此我们想把一些有明显边界、可延后加载的模块 “局部化”,同时还需要使得之前的代码最小变更。
采取的方案就是 独立出另一个 redux store
然后把作用域下的 useSelector 和 useDispatch 给替换成绑定了新 Context 的 Hook。
因为在 scope B
中,依然会在 UI 界面上使用一部份 scope A
的 command 和 state,所以,如果没有新的 Context 的话,在 scope B
中的 useSelector
和 useDispatch
就会被 scope B
的 ReactContext
遮蔽
但是 remesh
这边的情况似乎不需要这样,主要因为 store 并不依赖 domain 来创建,所以不会有我们产品项目中的问题。我们项目中主要需要的不是同一个 domain - logic 需要在 outer 和 inner 同时存在的问题,而是 code 需要分离的问题
from remesh.
@ninesunsabiu 明白你的意思了,对于 redux
单一 store
问题,我们在 remesh
之前的方案 pure-model
(现在仍在多个项目中广泛使用),也给出了基于 redux
的解决方案。
可以点击pure-model,权当参考~
from remesh.
@ninesunsabiu 明白你的意思了,对于
redux
单一store
问题,我们在remesh
之前的方案pure-model
(现在仍在多个项目中广泛使用),也给出了基于redux
的解决方案。可以点击pure-model,权当参考~
感谢指路。刚才大致浏览了一下,在 pure-model 这个方案下,和我们目前采用的方案类似的应该就是 useReactModel 这个 API。在子组件再具体使用 Model,而不是在 Root 直接静态 import Model。因为子组件有可能是一个 LazyComponent 所以这样的做法对 Code-Splitting 应该有些意义。
from remesh.
Related Issues (20)
- 调试问题:怎么样可以看到所有domain的state、query当前值 HOT 2
- 一个Query 使用useRemeshQuery和effect fromQuery同时订阅,effect的订阅会失效 HOT 8
- remesh4.0.0更新使用react useSyncExternalStore,导致无法正常使用remesh包。 HOT 2
- remesh如何在vue2.6中使用 HOT 5
- npm 包中的github链接错误 HOT 2
- remesh 一定需要搭配rxjs使用吗? HOT 1
- vue 2.7.14 中 使用remesh-vue报错app.provide为undefined HOT 1
- remesh在逻辑分离的同时怎么考虑到和UI同步的情况呢 HOT 5
- feat Serializable 支持 readonly HOT 4
- 中文文档有误 HOT 3
- 要是有个交流群或者discord就好了 HOT 6
- StorageExtern Type error HOT 2
- Remesh.domain 如何接收泛型 HOT 1
- 组件内部Query和Update一个状态,每次重新打开组件的时候,Query对应的State又被初始化为默认值了 HOT 3
- event和effect的使用问题 HOT 4
- query的类型没有自推倒,那类型如何定义? HOT 8
- Module not found: Error: Can't resolve 'use-sync-external-store/shim' in '/project/remesh-example/node_modules/remesh-react/esm' HOT 1
- ListModule 暴露 event 的必要性? HOT 3
- clearDomainStorageIfNeeded 清理之前可以有一个保留时间吗 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remesh.