new update
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import type { Product } from '@/models/products'
|
||||
|
||||
type ProductListHandler = (products: Product[]) => void
|
||||
|
||||
const handlers = new Set<ProductListHandler>()
|
||||
|
||||
export function subscribeProductListStream(handler: ProductListHandler) {
|
||||
handlers.add(handler)
|
||||
|
||||
return () => {
|
||||
handlers.delete(handler)
|
||||
}
|
||||
}
|
||||
|
||||
export function applyProductsListFromStream(products: Product[]) {
|
||||
if (!Array.isArray(products) || !products.length) {
|
||||
return
|
||||
}
|
||||
|
||||
handlers.forEach((handler) => handler(products))
|
||||
}
|
||||
Reference in New Issue
Block a user