Files
ghatreh_user/src/utils/productStreamBridge.ts
T

22 lines
497 B
TypeScript
Raw Normal View History

2026-06-29 15:27:35 +03:30
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))
}