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

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

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

Here is 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 " bob@aol.com " :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 that Clojure data structures are slightly different from JavaScript. Is it that Firebase doesn't like my Clojure map?

+5
source share
1 answer

Firebase expects a JavaScript object for API calls. You pass it the Clojure data structure (in this case, the map). You need to transform the Clojure data structure into a JavaScript object before passing it to Firebase functions.

So, instead of:

 (.push fb postData) 

you need to do:

 (.push fb (clj->js postData)) 
+7
source

Source: https://habr.com/ru/post/1209692/


All Articles