Fork me on GitHub
#portal
<
2021-03-23
>
plexus07:03:45

when using portal to inspect clojurescript values, does it honor datafy/nav? I tried implementing the protocols for my types (third party JS types) but it doesn't seem to be picking it up

djblue07:03:17

Nav should work automatically when you double click a value. Portal use to automatically datafy values when you nav-ed to them, however I removed this behavior instead for an explicit datafy call. The reason was that it made it harder if datafy was implemented for an object, but wasn't the desired behavior. Like I wanted to just slurp a file, or deref an atom. You can (cmd|ctrl) + shift + p or click the bottom right to open the command palette and call datafy explicitly for now 😬

djblue07:03:28

I could add it back now that portal has the concept of focusing a value, which is independent of both datafy and nav, which should solve the issues I had with the previous behavior.

djblue07:03:27

You can try version 0.6.4 (before I removed the auto-datafy) and see if everything works the way you expect

plexus08:03:06

that doesn't seem to be what I'm seeing

plexus08:03:43

maybe it's because I'm also implementing IPrintWithWriter?

djblue16:03:22

(deftype Point [x y]
  Datafiable
  (datafy [p] {:x (.-x p) :y (.-y p)})
  IPrintWithWriter
  (-pr-writer [this writer _]
    (write-all writer (pr-str (datafy this)))))

(tap> (Point. 1 2))

djblue16:03:19

☝️ worked for me when I explicitly called clojure.datafy/datafy on the point via the command palette

djblue02:03:08

@U07FP7QJ0 were you able to get it working?

plexus07:03:53

Tried it now, indeed hitting the >_ button and putting in clojure.datafy/datafy did the trick. Is that button documented somewhere? Are there plans to make it detect datafiable objects directly?

djblue14:03:43

The button is a new add so it's not documented yet, I'm thinking of putting together a tutorial page. What behavior would you expect of portal if you implemented datafy for your object? I've experimented a little and haven't found anything I've liked.

plexus07:03:09

I think ideally it would show it as the datafied value, and automatically invokes nav to drill down. I think that's what REBL does? The only downside to that I think is that it obscures the actual type, but maybe it can show a hint of the type. More advanced would be to allow toggling between the printed representation, and the datafied value. If I really had a magic wand I'd love to see a convention in the community for communicating the reader tag that should be associated with a certain datafied value. So in the above example, datafy could return something like ^{:reader-tag 'pixi/Point} {:x 10 :y 10}, and Portal would be able to render it as #pixi/Point {:x 10 :y 10}, but with colors and the ability to drill down.

3