-
Notifications
You must be signed in to change notification settings - Fork 87
Firebase
In the 60s, Doug Englebart used to make people try to write with a pencil that had a brick taped to the back of it. His point was, when you make something just a little more difficult, you end up doing a whole lot less of it. There would be no hamlet if shakespeare could only write with a 20ft log. It takes quite a bit of ceremony to add a receipe to this cookbook, and I think that's a shame, since a half baked recipe doesn't do any harm and can be a great starting point, so I'm going to start adding recipes to the wiki and hope that trends catches on and the wiki becomes the place people add stuff.
Here's how you make a reagent component that subscribes to a firebase path
(ns falsify.fire.core
(:require [cljsjs.firebase]
[clojure.string :as string]
[reagent.core :as r]))
(defn db-ref [path]
(.ref (js/firebase.database) (string/join "/" path)))
(defn on-value [ref a]
(.on ref "value"
(fn [e] (reset! a (.val e)))))
(defn card [app-state card-id]
(r/with-let [ref (db-ref ["test" "cards" card-id])
a (r/atom nil)
_ (on-value ref a)]
[:div
[:h1 @a]
[:input {:value @a
:on-change #(.set ref (.. % -target -value))}]]
(finally (.off ref))))
For a larger application using firebase and reagent, check out https://github.com/timothypratley/voterx