import type { TimelineManageable, TimelineToken, TimelineUpdate } from "atom.io" import type { Store } from "../store/store.ts" import { withdraw } from "../store/withdraw.ts" export function subscribeToTimeline( store: Store, token: TimelineToken, key: string, handleUpdate: (update: TimelineUpdate) => void, ): () => void { const tl = withdraw(store, token) store.logger.info(`👀`, `timeline`, token.key, `Adding subscription "${key}"`) const unsubscribe = tl.subject.subscribe(key, handleUpdate) return () => { store.logger.info( `🙈`, `timeline`, token.key, `Removing subscription "${key}" from timeline`, ) unsubscribe() } }