Comments (8)
我看看
from remesh.
from remesh.
我构造了一个测试用例,试图复现,但没有遇到你提的这个问题。
可以再排查一下,是不是意料之外地卸载了组件导致取消 effect 订阅了。
或者构造一个最小可复现 demo.
from remesh.
找到原因了,第一张图,我做了一个用户信息加载状态的判断,这个注释掉就没问题。
但是我在最外侧使用了RemeshScope,domain在组件销毁时不应该被销毁吧?
from remesh.
是的,RemeshScope 可以保活 domain 实例,理论上不会因为组件销毁所致的引用归零而自动回收掉。
不过,尽管 domain 不会被回收,但 domain-query
等领域资源还是会回收的。因此不再有引用的 domain-query
会被回收,因而 fromQuery(..)
的 observable
会 completed
掉。
from remesh.
对于 domain-query
层面的保活,目前可以通过下面的步骤来完成,后续可能考虑新增相关 API。
第一步,创建一个特殊的 domain-query
const HolderQuery = domain.query({
name: 'HolderQuery',
impl: ({ get }) => {
get(AQuery())
get(BQuery())
// 其他需要保活的 query
if (get(CQuery())) {
// 还可以根据动态条件选择保活
get(DQuery())
}
}
})
这个特殊的 Query,返回 undefined,这样它不会引起组件的更新(每次都一样的值),但会记住它依赖的其它 domain-query
第二步,在合适的组件层级里,订阅 HolderQuery
const HolderComponent = ({ children }: { children: ReactNode }) => {
const domain = useRemeshDomain(MyDomain())
useRemeshQuery(domain.query.HolderQuery())
// 手动保活 domain
useRemeshDomain(ChatDomain())
useRemeshDomain(UserDomain())
return <>{children}</>
}
// 这样用
<HolderComponent>
<XXRouterProvider />
</HolderComponent>
通过上述方式,我们同时按需保活的 domain 和 domain-query,实现了 RemeshScope 的功能并做得更多。
from remesh.
对于
domain-query
层面的保活,目前可以通过下面的步骤来完成,后续可能考虑新增相关 API。第一步,创建一个特殊的 domain-query
const HolderQuery = domain.query({ name: 'HolderQuery', impl: ({ get }) => { get(AQuery()) get(BQuery()) // 其他需要保活的 query if (get(CQuery())) { // 还可以根据动态条件选择保活 get(DQuery()) } } })这个特殊的 Query,返回 undefined,这样它不会引起组件的更新(每次都一样的值),但会记住它依赖的其它 domain-query
第二步,在合适的组件层级里,订阅 HolderQuery
const HolderComponent = ({ children }: { children: ReactNode }) => { const domain = useRemeshDomain(MyDomain()) useRemeshQuery(domain.query.HolderQuery()) // 手动保活 domain useRemeshDomain(ChatDomain()) useRemeshDomain(UserDomain()) return <>{children}</> } // 这样用 <HolderComponent> <XXRouterProvider /> </HolderComponent>通过上述方式,我们同时按需保活的 domain 和 domain-query,实现了 RemeshScope 的功能并做得更多。
好的,谢谢。建议在文档里提示一下这个问题,ScopeDomain介绍有些模糊了,会让人误解。
from remesh.
好的,这块确实得好好处理一下。
from remesh.
Related Issues (11)
- 想问下remesh的domain可以支持继承吗? HOT 2
- 如何从command中获取到一个返回值? HOT 4
- 同一个AsyncModule 同时(连续)调用多次,只会触发一次onSuccess HOT 2
- 调试问题:怎么样可以看到所有domain的state、query当前值 HOT 2
- 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
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.