chore: delete mem and use global type
This commit is contained in:
parent
1079eb0207
commit
437a6d82d6
5 changed files with 103 additions and 120 deletions
|
@ -96,7 +96,6 @@
|
|||
"date-fns": "^2.30.0",
|
||||
"idb-keyval": "^6.2.1",
|
||||
"lucide-react": "^0.263.0",
|
||||
"mem": "^9.0.2",
|
||||
"nanoid": "^4.0.2",
|
||||
"peerjs": "^1.4.7",
|
||||
"react-markdown": "^8.0.7",
|
||||
|
|
|
@ -41,9 +41,6 @@ dependencies:
|
|||
lucide-react:
|
||||
specifier: ^0.263.0
|
||||
version: 0.263.0(react@18.2.0)
|
||||
mem:
|
||||
specifier: ^9.0.2
|
||||
version: 9.0.2
|
||||
nanoid:
|
||||
specifier: ^4.0.2
|
||||
version: 4.0.2
|
||||
|
@ -5112,6 +5109,7 @@ packages:
|
|||
engines: {node: '>=6'}
|
||||
dependencies:
|
||||
p-defer: 1.0.0
|
||||
dev: true
|
||||
|
||||
/map-obj@1.0.1:
|
||||
resolution: {integrity: sha512-7N/q3lyZ+LVCp7PzuxrJr4KMbBE2hW7BT7YNia330OFxIf4d3r5zVpicP2650l7CPN6RM9zOJRl3NGpqSiw3Eg==}
|
||||
|
@ -5275,14 +5273,6 @@ packages:
|
|||
p-is-promise: 2.1.0
|
||||
dev: true
|
||||
|
||||
/mem@9.0.2:
|
||||
resolution: {integrity: sha512-F2t4YIv9XQUBHt6AOJ0y7lSmP1+cY7Fm1DRh9GClTGzKST7UWLMx6ly9WZdLH/G/ppM5RL4MlQfRT71ri9t19A==}
|
||||
engines: {node: '>=12.20'}
|
||||
dependencies:
|
||||
map-age-cleaner: 0.1.3
|
||||
mimic-fn: 4.0.0
|
||||
dev: false
|
||||
|
||||
/memorystream@0.3.1:
|
||||
resolution: {integrity: sha512-S3UwM3yj5mtUSEfP41UZmt/0SCoVYUcU1rkXv+BQ5Ig8ndL4sPoJNBUJERafdPb5jjHJGuMgytgKvKIf58XNBw==}
|
||||
engines: {node: '>= 0.10.0'}
|
||||
|
@ -5587,6 +5577,7 @@ packages:
|
|||
/mimic-fn@4.0.0:
|
||||
resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==}
|
||||
engines: {node: '>=12'}
|
||||
dev: true
|
||||
|
||||
/mimic-response@3.1.0:
|
||||
resolution: {integrity: sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==}
|
||||
|
@ -6021,6 +6012,7 @@ packages:
|
|||
/p-defer@1.0.0:
|
||||
resolution: {integrity: sha512-wB3wfAxZpk2AzOfUMJNL+d36xothRSyj8EXOa4f6GMqYDN9BJaaSISbsk+wS9abmnebVw95C2Kb5t85UmpCxuw==}
|
||||
engines: {node: '>=4'}
|
||||
dev: true
|
||||
|
||||
/p-is-promise@2.1.0:
|
||||
resolution: {integrity: sha512-Y3W0wlRPK8ZMRbNq97l4M5otioeA5lm1z7bkNkxCka8HSPjR0xRWmpCmc9utiaLP9Jb1eD8BgeIxTW4AIF45Pg==}
|
||||
|
|
|
@ -2,22 +2,16 @@ import { Remesh } from 'remesh'
|
|||
import { ListModule } from 'remesh/modules/list'
|
||||
import { nanoid } from 'nanoid'
|
||||
import { from, map, tap, merge } from 'rxjs'
|
||||
import mem from 'mem'
|
||||
import Storage from './externs/Storage'
|
||||
import { type Message } from '@/types'
|
||||
|
||||
export interface Message {
|
||||
id: string
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
const MessageListDomain = <T extends Message>() =>
|
||||
Remesh.domain({
|
||||
const MessageListDomain = Remesh.domain({
|
||||
name: 'MessageListDomain',
|
||||
impl: (domain) => {
|
||||
const storage = domain.getExtern(Storage)
|
||||
const storageKey = `${storage.name}.MESSAGE_LIST`
|
||||
|
||||
const MessageListModule = ListModule<T>(domain, {
|
||||
const MessageListModule = ListModule<Message>(domain, {
|
||||
name: 'MessageListModule',
|
||||
key: (message) => message.id
|
||||
})
|
||||
|
@ -33,25 +27,25 @@ const MessageListDomain = <T extends Message>() =>
|
|||
}
|
||||
})
|
||||
|
||||
const CreateItemEvent = domain.event<T>({
|
||||
const CreateItemEvent = domain.event<Message>({
|
||||
name: 'MessageList.CreateItemEvent'
|
||||
})
|
||||
|
||||
const CreateItemCommand = domain.command({
|
||||
name: 'MessageList.CreateItemCommand',
|
||||
impl: (_, message: Omit<T, 'id'>) => {
|
||||
const newMessage = { ...message, id: nanoid() } as T
|
||||
impl: (_, message: Omit<Message, 'id'>) => {
|
||||
const newMessage = { ...message, id: nanoid() }
|
||||
return [MessageListModule.command.AddItemCommand(newMessage), CreateItemEvent(newMessage), ChangeListEvent()]
|
||||
}
|
||||
})
|
||||
|
||||
const UpdateItemEvent = domain.event<T>({
|
||||
const UpdateItemEvent = domain.event<Message>({
|
||||
name: 'MessageList.UpdateItemEvent'
|
||||
})
|
||||
|
||||
const UpdateItemCommand = domain.command({
|
||||
name: 'MessageList.UpdateItemCommand',
|
||||
impl: (_, message: T) => {
|
||||
impl: (_, message: Message) => {
|
||||
return [MessageListModule.command.UpdateItemCommand(message), UpdateItemEvent(message), ChangeListEvent()]
|
||||
}
|
||||
})
|
||||
|
@ -78,13 +72,13 @@ const MessageListDomain = <T extends Message>() =>
|
|||
}
|
||||
})
|
||||
|
||||
const InitListEvent = domain.event<T[]>({
|
||||
const InitListEvent = domain.event<Message[]>({
|
||||
name: 'MessageList.InitListEvent'
|
||||
})
|
||||
|
||||
const InitListCommand = domain.command({
|
||||
name: 'MessageList.InitListCommand',
|
||||
impl: (_, messages: T[]) => {
|
||||
impl: (_, messages: Message[]) => {
|
||||
return [MessageListModule.command.SetListCommand(messages), InitListEvent(messages)]
|
||||
}
|
||||
})
|
||||
|
@ -92,7 +86,7 @@ const MessageListDomain = <T extends Message>() =>
|
|||
domain.effect({
|
||||
name: 'FormStorageToStateEffect',
|
||||
impl: () => {
|
||||
return from(storage.get<T[]>(storageKey)).pipe(map((messages) => InitListCommand(messages ?? [])))
|
||||
return from(storage.get<Message[]>(storageKey)).pipe(map((messages) => InitListCommand(messages ?? [])))
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -100,7 +94,7 @@ const MessageListDomain = <T extends Message>() =>
|
|||
name: 'FormStateToStorageEffect',
|
||||
impl: ({ fromEvent }) => {
|
||||
const createItem$ = fromEvent(ChangeListEvent).pipe(
|
||||
tap(async (messages) => await storage.set<T[]>(storageKey, messages))
|
||||
tap(async (messages) => await storage.set<Message[]>(storageKey, messages))
|
||||
)
|
||||
return merge(createItem$).pipe(map(() => null))
|
||||
}
|
||||
|
@ -125,6 +119,6 @@ const MessageListDomain = <T extends Message>() =>
|
|||
}
|
||||
}
|
||||
}
|
||||
})()
|
||||
})
|
||||
|
||||
export default mem(MessageListDomain)
|
||||
export default MessageListDomain
|
||||
|
|
|
@ -6,11 +6,10 @@ import MessageInput from '@/components/MessageInput'
|
|||
import MessageInputDomain from '@/domain/MessageInput'
|
||||
import MessageListDomain from '@/domain/MessageList'
|
||||
import { MESSAGE_MAX_LENGTH } from '@/constants'
|
||||
import { type Message } from '@/types'
|
||||
|
||||
const Footer: FC = () => {
|
||||
const send = useRemeshSend()
|
||||
const messageListDomain = useRemeshDomain(MessageListDomain<Message>())
|
||||
const messageListDomain = useRemeshDomain(MessageListDomain())
|
||||
const messageInputDomain = useRemeshDomain(MessageInputDomain())
|
||||
const text = useRemeshQuery(messageInputDomain.query.MessageQuery())
|
||||
const isPreview = useRemeshQuery(messageInputDomain.query.PreviewQuery())
|
||||
|
|
|
@ -3,10 +3,9 @@ import { useRemeshDomain, useRemeshQuery } from 'remesh-react'
|
|||
import MessageList from '@/components/MessageList'
|
||||
import MessageItem from '@/components/MessageItem'
|
||||
import MessageListDomain from '@/domain/MessageList'
|
||||
import { type Message } from '@/types'
|
||||
|
||||
const Main: FC = () => {
|
||||
const messageListDomain = useRemeshDomain(MessageListDomain<Message>())
|
||||
const messageListDomain = useRemeshDomain(MessageListDomain())
|
||||
const messageList = useRemeshQuery(messageListDomain.query.ListQuery())
|
||||
|
||||
return (
|
||||
|
|
Loading…
Reference in a new issue