Fork me on GitHub
#clojurescript
<
2023-03-14
>
martinklepsch10:03:25

hey all! I’m trying to extend https://firebase.google.com/docs/reference/js/firestore_.timestamp with p/Datafiable but I’m not quite sure how to “point at” the type in my extend-type call, the below isn’t working. Anyone know what I’m missing?

(extend-type firestore/Timestamp
  protocols/Datafiable
  (datafy [this]
    {:some :data}))

thheller10:03:52

looks correct. what is not working?

thheller10:03:25

assuming of course firestore/Timestamp is an actual thing and not nil?

martinklepsch10:03:36

(d/datafy some-timestamp)
Doesn’t return the map

thheller10:03:49

and what is some-timestamp?

martinklepsch10:03:02

an instance of firestore/Timestamp

thheller10:03:41

so, (instance? firestore/Timestamp some-timestamp) is true?

martinklepsch11:03:11

the timestamp logs as

#object[Timestamp [object Object]]

martinklepsch11:03:47

I wonder if this has anything to do with the slightly weird(?) constructor definition here? https://firebase.google.com/docs/reference/js/firestore_.timestamp.md#constructors

thheller11:03:58

check what (type some-timestamp) is exactly

thheller11:03:21

what is weird about it?

martinklepsch11:03:38

#object[Timestamp]

thheller11:03:49

not in the REPL, use the browser console

thheller11:03:06

it displays more info and also the prototype chain

thheller11:03:27

js/console.log it I mean

martinklepsch11:03:11

I don’t know if browser console is super helpful here because the node and browser APIs vary a bit.

martinklepsch11:03:20

which makes me notice that the earlier link was to the wrong docs: https://firebase.google.com/docs/reference/node/firebase.firestore.Timestamp

thheller11:03:00

maybe use console.dir instead of log

thheller11:03:21

should see the prototype chain somewhere

thheller11:03:04

just want to find out if the timestamp is in there and what you actually have is some wrapped thing

thheller11:03:25

what might work is (extend-type (type some-timestamp) p/Datafiable ...)

thheller11:03:00

hmm so datafy is in there. should work then

martinklepsch11:03:09

just noticed that as well

martinklepsch11:03:16

let me re-read datafy docs

thheller11:03:39

try the extend-type anyways. JS types are funky sometimes. these also seem to be generated from protobuf which makes wrapping likely

martinklepsch11:03:23

Ok, it was all working as expected, I extended the type in the wrong env (browser vs. node) facepalm

Olaleye Blessing17:03:17

I have a Phoenix Liveview + Clojurescript app. How can I run a function in clojurescript every time a page is loaded? I want to run the function when a user moves from page A to B to C

thheller17:03:41

sounds more like a liveview question than cljs? how would you do it in JS?

Olaleye Blessing17:03:26

Maybe I would listen to DOMContentLoaded on each page.