* Updates every subscription whose `shouldUpdate` accepts the event. * @param cache - The cache to compute the values from. * @param event - The cache event. * @param schedule - Runs each update, receiving the subscription's id so repeated updates of the * same subscription can be merged
(
cache: Accessor<TCache>,
event: TEvent,
schedule: (update: () => void, id: symbol) => void,
)
| 46 | * same subscription can be merged. |
| 47 | */ |
| 48 | function notify( |
| 49 | cache: Accessor<TCache>, |
| 50 | event: TEvent, |
| 51 | schedule: (update: () => void, id: symbol) => void, |
| 52 | ) { |
| 53 | for (const [id, subscription] of subscriptions) { |
| 54 | if (!subscription.shouldUpdate(event)) continue |
| 55 | schedule(() => { |
| 56 | if (subscriptions.has(id)) subscription.update(cache) |
| 57 | }, id) |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return { register, notify } |
| 62 | } |