firebase-cljs
firebase-cljs copied to clipboard
clj->js into firebase, then js->clj out is not the same
@flyboarder, been working with this for a bit now and it's going pretty well!
I have noticed an odd issue, it seems that I get different values sending data into the firebase db vs pulling data out.
data goes in:
#js {:items #js {:1 #js {:id 1, :date 1489930651500}, :2 #js {:id 2, :date 1489930651652}}}
data comes out:
{items [nil {date 1489930651500, id 1} {date 1489930651652, id 2}]}
I'm doing:
(fbdb/listen @*ref* "value" #(println (js->clj (fbsnap/val %))))
It's frustrating as the correct values appear to be being stored in firebase, but the keys in the hash-maps seem to be repeatedly dropped. It seems to be pulling out objects as arrays?
I've tried js->clj with and without keywordize-keys and it doesn't seem to make any difference.
Is this an actual bug, or am I just doing something silly?
Ok, so having done a little more digging, it seems to be a bug in firebase?
As far as I can work out if you use int keys, it always comes out as an array. So my solution has been to add "key-" as a prefix to my int keys going in, and remove them going out.
Tested what's being returned using it as a double check:
var uid = firebase.database().app.auth().currentUser.uid;
firebase.database().ref('users/' + uid).on('value', function(snapshot) {
console.log("FROM FIREBASE:", snapshot.val());
});
Maybe worth documenting this?
This is actually correct firebase behavior. https://firebase.googleblog.com/2014/04/best-practices-arrays-in-firebase.html?m=1