DINO
DINO9mo ago

Make Zustand store scalable

Hello, This is my Zustand store state type:
type WaitlistState = {
counterSaleWaitlist: CounterSaleWaitlistItemType[]
salesInvoiceWaitlist: SalesInvoiceWaitlistItemType[]
purchaseInvoiceWaitlist: PurchaseInvoiceWaitlistItemType[]
addCounterSaleItem: (data: CounterSaleWaitlistItemType['data']) => void
addSalesInvoiceItem: (data: SalesInvoiceWaitlistItemType['data']) => void
addPurchaseInvoiceItem: (data: PurchaseInvoiceWaitlistItemType['data']) => void
deleteItem: (date: string) => void
deleteList: (
list: 'counterSaleWaitlist' | 'salesInvoiceWaitlist' | 'purchaseInvoiceWaitlist'
) => void
deleteAll: () => void
}
type WaitlistState = {
counterSaleWaitlist: CounterSaleWaitlistItemType[]
salesInvoiceWaitlist: SalesInvoiceWaitlistItemType[]
purchaseInvoiceWaitlist: PurchaseInvoiceWaitlistItemType[]
addCounterSaleItem: (data: CounterSaleWaitlistItemType['data']) => void
addSalesInvoiceItem: (data: SalesInvoiceWaitlistItemType['data']) => void
addPurchaseInvoiceItem: (data: PurchaseInvoiceWaitlistItemType['data']) => void
deleteItem: (date: string) => void
deleteList: (
list: 'counterSaleWaitlist' | 'salesInvoiceWaitlist' | 'purchaseInvoiceWaitlist'
) => void
deleteAll: () => void
}
In the future I will add more invoices (up to 10), and I kind of don't like doing something like:
counterSaleWaitlist: CounterSaleWaitlistItemType[]
salesInvoiceWaitlist: SalesInvoiceWaitlistItemType[]
purchaseInvoiceWaitlist: PurchaseInvoiceWaitlistItemType[]
xInvoiceWaitlist: XInvoiceWaitlistItemType[]
yInvoiceWaitlist: YInvoiceWaitlistItemType[]
zInvoiceWaitlist: ZInvoiceWaitlistItemType[]
addCounterSaleItem: (data: CounterSaleWaitlistItemType['data']) => void
addSalesInvoiceItem: (data: SalesInvoiceWaitlistItemType['data']) => void
addPurchaseInvoiceItem: (data: PurchaseInvoiceWaitlistItemType['data']) => void
addPurchaseX: (data: XInvoiceWaitlistItemType['data']) => void
addPurchaseY: (data: YInvoiceWaitlistItemType['data']) => void
addPurchaseZ: (data: ZInvoiceWaitlistItemType['data']) => void
// ...
counterSaleWaitlist: CounterSaleWaitlistItemType[]
salesInvoiceWaitlist: SalesInvoiceWaitlistItemType[]
purchaseInvoiceWaitlist: PurchaseInvoiceWaitlistItemType[]
xInvoiceWaitlist: XInvoiceWaitlistItemType[]
yInvoiceWaitlist: YInvoiceWaitlistItemType[]
zInvoiceWaitlist: ZInvoiceWaitlistItemType[]
addCounterSaleItem: (data: CounterSaleWaitlistItemType['data']) => void
addSalesInvoiceItem: (data: SalesInvoiceWaitlistItemType['data']) => void
addPurchaseInvoiceItem: (data: PurchaseInvoiceWaitlistItemType['data']) => void
addPurchaseX: (data: XInvoiceWaitlistItemType['data']) => void
addPurchaseY: (data: YInvoiceWaitlistItemType['data']) => void
addPurchaseZ: (data: ZInvoiceWaitlistItemType['data']) => void
// ...
Are there any common practices to handle such a thing? Thanks.
6 Replies
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
DINO
DINOOP9mo ago
I like Type more, and I have seen it used a lot.
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
DINO
DINOOP9mo ago
I don't mind the long name. Interfaces usually starts with the letter I
Unknown User
Unknown User8mo ago
Message Not Public
Sign In & Join Server To View
DINO
DINOOP8mo ago
Thank you very much for the help ❤️