Comments (8)
理论上不会产生这个问题,需要检查一下 getQueries
自身的类型定义是否健全。
此外,Remesh
约束了命名规范,getBuyer
不是合法的 Query
,合法的 Query name
是大写字母开头且以 Query
作为后缀。
from remesh.
你的截图里的代码,有很多不规范的地方。
获取 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
}
}
}
类型推导如下:
from remesh.
Thank feedback. We will check it later:-)
from remesh.
将query, command, events都独立文件处理,以免domain过大。但这样query的类型就变成any了
from remesh.
想将query, command, events都独立文件处理,避免domain文件太大,有没有好的解决方案?
from remesh.
from remesh.
这里再拆分一个BuyerModule
,理解到了。但我的想法是当成员比较小时,不必单独拆分。
之前的问题,单个domain
怎么去拆分它的query, command, event, effect作为文件独立管理,一个简单的todoDomain,也有240多行的代码,如何避免domain
文件太长难以阅读、多人协作的文件冲突等,如何解决请指教。
from remesh.
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)
- 一个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
- 可以实现多实例吗 HOT 8
- 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
- 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
- StartedEvent effect 依赖于 dom 的挂载, dom 的挂载依赖于 StartedEvent 应该怎么实现呢 HOT 1
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.