* 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. Defaults to running it right away.
(
cache: Accessor<TCache>,
event: TEvent,
schedule: (update: () => void) => void = (update) => update(),
)
| 45 | * @param schedule - Runs each update. Defaults to running it right away. |
| 46 | */ |
| 47 | function notify( |
| 48 | cache: Accessor<TCache>, |
| 49 | event: TEvent, |
| 50 | schedule: (update: () => void) => void = (update) => update(), |
| 51 | ) { |
| 52 | for (const [id, subscription] of subscriptions) { |
| 53 | if (!subscription.shouldUpdate(event)) continue |
| 54 | schedule(() => { |
| 55 | if (subscriptions.has(id)) subscription.update(cache) |
| 56 | }) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return { register, notify } |
| 61 | } |