Giter Club home page Giter Club logo

Comments (8)

Lucifier129 avatar Lucifier129 commented on May 28, 2024 2

理论上不会产生这个问题,需要检查一下 getQueries 自身的类型定义是否健全。

此外,Remesh 约束了命名规范,getBuyer 不是合法的 Query,合法的 Query name 是大写字母开头且以 Query 作为后缀。

from remesh.

Lucifier129 avatar Lucifier129 commented on May 28, 2024 1

你的截图里的代码,有很多不规范的地方。

获取 events 类型其实很简单,只要在编辑器里 hover 上去查看一个普通 event 的类型,复制出来组成一个 object type 即可。

你的场景其实是要定义一个 Remesh Modules,一般做法如下:

import { Remesh, RemeshCommandOutput, RemeshDomainContext } from 'remesh'

type Buyer = {

}

type OrderState = {
  buyer: Buyer
}

/**
 * 用 getters, setters and callbacks
 * 不要直接依赖具体的 domain 对象
 */
type BuyerModuleOptions = {
  onBuyerUpdated: () => RemeshCommandOutput
}

const BuyerModule = (domain: RemeshDomainContext, options: BuyerModuleOptions) => {
  const OrderState = domain.state({
    name: 'OrderState',
    default: {}
  })


  const BuyerUpdatedEvent = domain.event({
    name: 'BuyerUpdatedEvent',
  })

  const UpdateBuyerCommand = domain.command({
    name: 'UpdateBuyerCommand',
    impl: ({ get }, buyer: Buyer) => {
      const newState = {
        ...get(OrderState),
        buyer
      }

      return [
        OrderState.new(newState),
        BuyerUpdatedEvent(),
        options.onBuyerUpdated()
      ]
    }
  })


  return {
    command: {
      UpdateBuyerCommand
    },
    event: {
      BuyerUpdatedEvent
    }
  }
}

类型推导如下:

image

from remesh.

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

Thank feedback. We will check it later:-)

from remesh.

soakit avatar soakit commented on May 28, 2024

image

将query, command, events都独立文件处理,以免domain过大。但这样query的类型就变成any了

from remesh.

soakit avatar soakit commented on May 28, 2024

image

想将query, command, events都独立文件处理,避免domain文件太大,有没有好的解决方案?

from remesh.

soakit avatar soakit commented on May 28, 2024

image
还有一个问题,这个传入的events的类型怎么获取?

from remesh.

soakit avatar soakit commented on May 28, 2024

这里再拆分一个BuyerModule,理解到了。但我的想法是当成员比较小时,不必单独拆分。

之前的问题,单个domain怎么去拆分它的query, command, event, effect作为文件独立管理,一个简单的todoDomain,也有240多行的代码,如何避免domain文件太长难以阅读、多人协作的文件冲突等,如何解决请指教。

示例代码

from remesh.

Lucifier129 avatar Lucifier129 commented on May 28, 2024

240 行的 todo domain 是正常的,文件长不意味着一定会难以阅读,还是要看代码自身的复杂度。多人协作文件冲突按照 git 的方式解决。

单个 domain 也不必按照 query, command, event, effect 的分类进行拆分,而是按照 feature 来拆分,一个 feature 可以有自己的一套 query, command, event ,effect,按照上面示意过的 Remesh Module 的风格进行设计和封装。跟 react component 通过 react hooks 拆分出去是一样的。

todo domain 这里有个拆分版的 todo domain,总体代码更长,但更灵活和解耦。

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.