devout: replay relevant events to new subscriber

This commit is contained in:
Daniel Barlow
2024-04-26 17:03:30 +01:00
parent a116fe084a
commit cf9cadd212
2 changed files with 13 additions and 0 deletions

View File

@@ -53,6 +53,9 @@
:add (fn [_ event-string] (record-event db subscribers event-string))
:at-path (fn [_ path] (. db path))
:subscribe (fn [_ id callback terms]
(let [past-events (find-in-database db terms)]
(each [_ e (pairs past-events)]
(callback e)))
(tset subscribers id {: callback : terms }))
:unsubscribe (fn [_ id] (tset subscribers id nil))
}))