Giter Club home page Giter Club logo

Comments (8)

Lucifier129 avatar Lucifier129 commented on May 24, 2024 1

@ninesunsabiu 嵌套式隔离是指什么形式?部分 domain 来自内层,部分 domain 来自外层?

对于这种场景,可以通过添加指定的 scope keydomain arg 里,也就是说在内层使用的是 MyDomain({ scope: 'inner', ...others }) ,而外层使用的是 MyDomain({ scope: 'outer' , ...others})。这样两个 domain 分别是不同的实例。

通过参数化 domain 去管理多实例,用参数设计来管理 scope 问题。这个策略更加灵活,因为它们仍在同一个 store 里,可以互相通讯(domain.getDomain)和组合。

from remesh.

hourong88 avatar hourong88 commented on May 24, 2024

from remesh.

github-actions avatar github-actions commented on May 24, 2024

Thank feedback. We will check it later:-)

from remesh.

Lucifier129 avatar Lucifier129 commented on May 24, 2024

@wqy8593521 有很多种方法,要看具体你的场景。

  • 分别使用 <RemeshRoot />把两个区域间隔开,就得到了两个独立的 RemeshStore 了。其中,它们内部的所有 domain 实例都是互不影响的
  • 使用带参数的 RemeshDomain(arg),如MyDomain('id1')MyDomain('id2') 对应的是两个不同的 domain 实例。

from remesh.

ninesunsabiu avatar ninesunsabiu commented on May 24, 2024

@wqy8593521 有很多种方法,要看具体你的场景。

  • 分别使用 <RemeshRoot />把两个区域间隔开,就得到了两个独立的 RemeshStore 了。其中,它们内部的所有 domain 实例都是互不影响的

如果是兄弟层级的需要隔离开,用两个 <RemeshRoot /> 可以,如果想要嵌套形式的隔离的话,内层的会遮蔽祖先层级。
是否考虑像 react-redux 那样,可以自定持有 storeReactContext 并且能有 createUseRemeshXXX(Context) 这样二次创造 Hook 的能力?

from remesh.

ninesunsabiu avatar ninesunsabiu commented on May 24, 2024

嵌套式隔离是指什么形式?部分 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 中的 useSelectoruseDispatch 就会被 scope BReactContext 遮蔽


但是 remesh 这边的情况似乎不需要这样,主要因为 store 并不依赖 domain 来创建,所以不会有我们产品项目中的问题。我们项目中主要需要的不是同一个 domain - logic 需要在 outer 和 inner 同时存在的问题,而是 code 需要分离的问题

from remesh.

Lucifier129 avatar Lucifier129 commented on May 24, 2024

@ninesunsabiu 明白你的意思了,对于 redux 单一 store 问题,我们在 remesh 之前的方案 pure-model(现在仍在多个项目中广泛使用),也给出了基于 redux 的解决方案。

可以点击pure-model,权当参考~

from remesh.

ninesunsabiu avatar ninesunsabiu commented on May 24, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.