This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-24
Channels
- # announcements (3)
- # babashka (23)
- # beginners (35)
- # cider (3)
- # clara (3)
- # clj-kondo (14)
- # cljdoc (1)
- # cljs-dev (1)
- # clojure (82)
- # clojure-austin (9)
- # clojure-europe (5)
- # clojurescript (23)
- # conjure (62)
- # cursive (73)
- # defnpodcast (1)
- # emacs (3)
- # ethereum (1)
- # gratitude (1)
- # hyperfiddle (12)
- # introduce-yourself (1)
- # leiningen (2)
- # lsp (44)
- # malli (7)
- # polylith (2)
- # portal (17)
- # re-frame (5)
- # reitit (3)
- # sci (8)
- # shadow-cljs (5)
- # tools-build (11)
Just wrote up a guide around https://github.com/djblue/portal/blob/master/doc/guides/promises.md and JavaScript promises>, hope it can be useful to some :thumbsup:
This gist of it is, you can specialize tap> for promises:
(require '[portal.api :as p])
(defn async-submit [value]
(if-not (instance? js/Promise value)
(p/submit value)
(.then value p/submit)))
(add-tap #'async-submit)
(tap> (async-fn)) ;; :hello
Also, if you aren't a fan of the default tap list behavior in portal, https://github.com/djblue/portal/blob/master/doc/guides/custom-taps.md 👌
This sounds amazing! If I'm not mistaken, this can be used just for changing the default portal view ❤️
Ohh, also, a long time ago Portal use to automatically datafy all submitted values but I felt like that shouldn't be the default. If you want that behavior, try:
(require '[clojure.datafy :as d])
(require '[portal.api :as p])
(def submit (comp p/submit d/datafy))
(add-tap #'submit)
(tap> *ns*)
This is useful for folks who are dealing with Java/JavaScript objects and have extended the clojure.core.protocols/Datafiable
protocol to those objects. Or perhaps, the objects are coming from a library that has done the work.
next.jdbc
is a good example on the backend so you can navigate thru the database.
@U04V70XH6 I'd like to try the next.jdbc example specifically. Is there some blogpost/guide on this?
next.jdbc
automatically makes result sets datafiable and navigable, with an assumption that FKs are named <table>id
or <table>_id
, so if you have a result set from next.jdbc
displayed in Portal, you can datafy a row and then nav to other tables from any FK columns. I don't know if I have an up-to-date video example of that online -- and I haven't tried it since Portal 24 came out (which removes the auto-datafication of values).
I blogged about the machinery when it was first introduced, https://corfield.org/blog/2018/12/03/datafy-nav/ (three and a half years ago -- yikes, time flies!).
For example, suppose I execute this code:
(jdbc/execute! (-> a :database :pooled-db :datasource)
["select * from membership m join membershipPackage p on m.membershippackageid = p.id"])
and that produces rows that have a user_id
column. When I highlight the value of user_id
in one of those rows in Portal and press enter
(or ctrl-j nav
), that will call nav
with the row, the key (`user_id`), and the value, e.g., 9
and that in turn will cause next.jdbc
to do select * from user where id = 9
and then Portal displays that and you can continue to navigate into column values across the database.In addition, if you require next.jdbc.datafy
then a lot of raw JDBC data types become navigable -- you can call .getMetadata
on a Connection
and datafy
(`ctrl-j datafy`) the Java object to get a "bean" view of the metadata, which contains some additional keys like :all-tables
which you can nav
into and next.jdbc
will fetch all the table data from the schema and display that in Portal.
Amazing, thank you very much for taking the time to write this out @U04V70XH6! I'm going to try this out in the next few days 🥳