firemore
firemore copied to clipboard
Hide the asynchronous nature with re-frame?
Think through on how we can hide the asynchronous nature of the read and write operations with re-frame. Basically make it similar to a XMLHTTPRequest in re-frame.
Maybe just two event handlers like :firemore/watch
:firemore/write
?
So I have done some real thought about this and I think this should actually be done within a different project (maybe firemore-re-frame
). re-frame introduces a very different way of thinking and dealing with events than "raw" atoms. The way that this is handled in re-frame will be different than the way it will be handled with [reagent] (r)atoms.
(reg-event-fx
:watch-cities-handler
(fn [{:keys [db]} _]
{:firemore-watch {
:reference [:cities {}] ;; required (the source)
:event [:write-to-db] ;; required (the event handler)
;; NOTE: path defaults to being the same as :reference
:path [:my-cities] ;; optional (the destination)
}}))
(reg-event-fx
:write-to-db
(fn [{:keys [db]} [_ reference path result]]
{:db (assoc-in db path result)}))
Also thinking that maybe we can have two cofx
"I want to register a handler that is called whenever I get a new value"
:firemore-watch-fx
(takes :reference
, :event
and optional :path
)
AND
"I just want to write directly to the database"
:firemore-watch-db
(takes :reference
and optional :path
)