Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to firebase.push in Clojurescript? Is my data correct?

I'm am trying to .push some data to my Firebase but I'm getting this error in my Chrome console:

Uncaught Error: Firebase.push failed: first argument contains an invalid key (cljs$lang$protocol_mask$partition0$) in property 'arr.0'. Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"

Here's my code:

fb (js/Firebase. "https://example.firebaseio.com/example-listings")

(def app-state (atom {"post" { :first_name "Billy"
                               :last_name "Bob"
                               :location "CA"
                               :email "[email protected]"
                               :website "www.pwt.com"
                          }}))

(def postData (get-in @app-state ["post"]))
(.push fb postData)

I also tried replacing the keys with strings :first_name with "first_name". I understand Clojure's data structures are a bit different from JavaScript. Is it the case that Firebase isn't liking my Clojure map?

like image 385
Henry Zhu Avatar asked Dec 22 '14 08:12

Henry Zhu


1 Answers

Firebase expects a JavaScript object to its API calls. You are passing it a Clojure data structure (in this case a map). You have to convert your Clojure data structure to a JavaScript object before passing it to the Firebase function.

So instead of:

(.push fb postData)

you need to do:

(.push fb (clj->js postData))
like image 125
Symfrog Avatar answered Oct 07 '22 19:10

Symfrog