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
@plexus were you able to get it working?
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?
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.
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.
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 😬
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.
You can try version 0.6.4
(before I removed the auto-datafy) and see if everything works the way you expect
https://github.com/djblue/portal/blob/master/examples/node/dev/user.cljs#L17-L19 is a node example
that doesn't seem to be what I'm seeing
maybe it's because I'm also implementing IPrintWithWriter?
(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))
☝️ worked for me when I explicitly called clojure.datafy/datafy
on the point via the command palette