-
Notifications
You must be signed in to change notification settings - Fork 41
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
query的类型没有自推倒,那类型如何定义? #88
Comments
Thank feedback. We will check it later:-) |
理论上不会产生这个问题,需要检查一下 此外, |
你的截图里的代码,有很多不规范的地方。 获取 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
}
}
} 类型推导如下: |
这里再拆分一个 之前的问题,单个 |
240 行的 todo domain 是正常的,文件长不意味着一定会难以阅读,还是要看代码自身的复杂度。多人协作文件冲突按照 git 的方式解决。 单个 domain 也不必按照 query, command, event, effect 的分类进行拆分,而是按照 feature 来拆分,一个 feature 可以有自己的一套 query, command, event ,effect,按照上面示意过的 todo domain 这里有个拆分版的 todo domain,总体代码更长,但更灵活和解耦。 |
No description provided.
The text was updated successfully, but these errors were encountered: