remesh-js / remesh Goto Github PK
View Code? Open in Web Editor NEWA CQRS-based DDD framework for large and complex TypeScript/JavaScript applications
Home Page: https://remesh-js.github.io/remesh/dist/index.html
License: MIT License
A CQRS-based DDD framework for large and complex TypeScript/JavaScript applications
Home Page: https://remesh-js.github.io/remesh/dist/index.html
License: MIT License
比如我有一个CreateCommand,我需要返回创建之后的id用于后续异步的继续对这个id资源做某些操作。
比如,loading这种场景,或者获取完数据后需要特殊处理的场景,怎么结合remesh起来用呢?
比如我们用AsyncModule,如果还要在页面上监听onSuccess来处理的话,每个请求都要这么写吗
在使用 HistoryModule
时,由于范型 T extends SerializableArray | SerializableObject
导致无法使用
由于我项目中是搭配使用了 @effect/schema
,从中推断出来的类型都会带上 readonly
修饰,所以如果 Serializable
能够支持 readonly
的话,应该就可用。
考虑到 readonly
修饰的数据,并不会实际对序列化的实现或者语义造成影响,所以我觉得在库层面进行支持是有理由的。
export type SerializableArray = Serializable[] | ReadonlyArray<Serializable>;
export type SerializableObject = {
[key: string]: Serializable;
} | {
readonly [key: string]: Serializable;
};
看了文档和示例,都是使用rxjs
请教下,因为老项目升级成本太高,想试试看在vue 2.6下使用remesh,是否可以有demo可以提供呢
在看 TodoList example 时发现event
产生依赖于TodoListModule
的command
,但是 command
实现细节是在remesh
内部的,需要使用者确定command
确实对list
产生了修改,如果ListModule
对外暴露ListChangedEvent、ListItemAddedEvent
等事件,外部就确定事件已发生可以直接使用。不知道有没有必要呢?如果有必要的话我想尝试提一下pr~
当发布一个命令后 所有组件都会同步更新状态 状态是全局唯一的 能否实现多实例 组件不同实例下状态互不影响
每次打开 TypeGridFilterCmp 组件,值都是 空 '', 请问为什么呀?
import { Remesh } from 'remesh';
export type DataType = '' | 'MTD';
const HeaderFilterDomain = Remesh.domain({
name: 'HeaderFilterDomain',
impl: (domain) => {
const DataTypeState = domain.state<DataType>({
name: 'DataTypeState',
default: '',
});
const DataTypeQuery = domain.query({
name: 'DataTypeQuery',
impl: ({ get }) => {
return get(DataTypeState());
},
});
const UpdateDataTypeCommand = domain.command({
name: 'UpdateDataTypeCommand',
impl: (_, type: DataType) => {
return DataTypeState().new(type);
},
});
return {
query: { DataTypeQuery },
command: { UpdateDataTypeCommand },
event: {},
};
},
});
export default HeaderFilterDomain;
function TypeGridFilterCmp(props: IProps) {
const { onClick } = props;
const send = useRemeshSend();
const headerFilterDomain = useRemeshDomain(HeaderFilter());
const dataType = useRemeshQuery(headerFilterDomain.query.DataTypeQuery());
console.log('log: dataType', dataType);
const updateDataType = (type: DataType) => {
send(headerFilterDomain.command.UpdateDataTypeCommand(type));
};
return (
<div>
<Grid columns={1} className="pick-type-grid">
<Grid.Item>
<ul>
<li
className={dataType === '' ? 'active' : ''}
onClick={() => {
updateDataType('');
}}
>
1
<div className="wait-select-icon" />
</li>
<li
className={dataType === '2' ? 'active' : ''}
onClick={() => {
updateDataType('MTD');
}}
>
2
<div className="wait-select-icon" />
</li>
</ul>
</Grid.Item>
</Grid>
</div>
);
}
![image](https://user-images.githubusercontent.com/32118686/221463572-ec018256-502f-42ec-96ca-6547573f154a.png)
试了下,在remesh-vue中的app.provide是undefined的,这块用法不对吗
因为vue2.7也没有createApp
只能Vue.use(RemeshVue(remeshStore))
如果说直接用provide而不用app.provide,那只能在setup中使用,也没法被绑到app上
这块能给的demo吗,Thanks♪(・ω・)ノ
Originally posted by @FEYeh in #72 (comment)
我觉得这是一个场景,一个 domain 有多个实例,不可能都用 RemeshDomainHolderContainer 保活,但也允许存活一段时间,一段时间后再进行清理,这期间再次挂载可以复用。
脚手架:create-react-app
package.json
{
"name": "remesh-demo",
"version": "0.1.0",
"private": true,
"type": "module",
"dependencies": {
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1",
"@types/jest": "^27.0.1",
"@types/node": "^16.7.13",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"remesh": "^4.0.0",
"remesh-react": "^4.0.0",
"rxjs": "^7.5.6",
"web-vitals": "^2.1.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/typescript": "^2.0.0",
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
}
}
README_zh_CN.md
特性第5:可变状态
英文版是,immutable state
应该是,不可变状态
现在有这样一个业务方法
const downloadId = downloader.startDownload(url, {
onProgress: () => {},
onFinish: () => {},
onFailed: () => {},
})
download.cancelDownload(downloadId)
使用remesh定义如下模型
downloadCommand
cancelDownloadCommand
downloadStartedEvent
progressUpdatedEvent
downloadSuccessEvent
downloadFailedEvent
按我的理解 download.startDownload发生发生在downloadStartedEvent的effect,如果下载的过程中发起了cancelDownloadCommand,此时downloadId应该在state里面了但是不清楚什么时机保存的,是应该在effect触发一个额外的事件downloadIdGotEvent吗?
感觉remesh的设计很有前景,但没发现有什么交流渠道
domain.ts
// 示例在 impl 中可以接收泛型 T
export interface MessageSimple {
id: string
[key: string]: any
}
export const MessageListDomain = Remesh.domain({
name: 'MessageListDomain',
impl:(domain) =>{
const CreateItemEvent = domain.event<T>({
name: 'MessageList.CreateItemEvent'
})
const CreateItemCommand = domain.command({
name: 'MessageList.CreateItemCommand',
impl: (_, message: T) => {
// ...
return [CreateItemEvent(message)]
}
})
}
})
index.ts
import { MessageListDomain } from './domain.ts'
export interface Message {
id: string
time: 'xxxx',
body: 'xxxx'
}
// 如何才能像这样将 Message 传递给 MessageListDomain 中的 T?
const messageListDomain = useRemeshDomain(MessageListDomain<Message>())
一种方式是写成 iife:
domain.ts
export interface MessageSimple {
id: string
[key: string]: any
}
export const MessageListDomain = <T extends MessageSimple>()=> Remesh.domain({
...
const CreateItemEvent = domain.event<T>....
})()
index.ts
const messageListDomain = useRemeshDomain(MessageListDomain<Message>())
如果这样定义,那么在 index.ts 可以传入 Message,但是 Remesh.domain 变成了在外部调用 useRemeshDomain 时初始化,多次调用初始化多次
目前的解决方案是,导出时使用 memoize 缓存 MessageListDomain 执行结果防止重复执行,有更好的方式吗
比如 定义了一个Domain叫 AnimalDomain, 我想对它进行不同的实现,然后在另外一个ManageDomain中引用AnimalDomain, 根据注入的参数不同,让AnimalDomain呈现为不同的子实现。目前似乎我只能通过引用不同的Domain来实现,或者借助map
在redux-devtools中只能看到action,有什么方法可以看到某一个domain的所有state或者query吗?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.