This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-18
Channels
- # aws (1)
- # babashka (35)
- # beginners (52)
- # biff (4)
- # calva (55)
- # cider (19)
- # clojure (54)
- # clojure-dev (3)
- # clojure-europe (23)
- # clojure-nl (1)
- # clojure-norway (3)
- # clojure-uk (2)
- # clojurescript (9)
- # code-reviews (3)
- # datahike (1)
- # fulcro (1)
- # funcool (4)
- # graalvm (21)
- # gratitude (2)
- # java (5)
- # jobs (2)
- # joyride (1)
- # kaocha (13)
- # malli (2)
- # off-topic (22)
- # other-languages (11)
- # pathom (4)
- # re-frame (35)
- # reagent (3)
- # reitit (3)
- # releases (2)
- # remote-jobs (1)
- # rum (1)
- # shadow-cljs (42)
- # sql (18)
- # tools-deps (72)
- # web-security (6)
- # xtdb (15)
How folks do you survive in REPL on promise-heavy CLJS projects? Here is approach I'm about to try:
(ns p-dev
"Utilities for REPL-driven development with Promise-heavy tasks."
(:require
[promesa.core :as p])
#?(:cljs (:require-macros [p-dev])))
(def ^:private pending (atom nil))
(defn- get-pending []
(deref pending))
(defn- set-pending! [value]
(reset! pending value))
(defmacro p-do
[& body]
`(let [pending# (get-pending)]
(set-pending!
(p/do
pending#
~@body))))
(defmacro p-def
[name p-val]
`(p-do
(p/let [val# ~p-val]
(def ~name val#))))
Usage:
(ns playground
(:require
[p-dev :refer-macros [p-def p-do]]
[promesa.core :as p]))
(defn defer-value [value]
(p/create
(fn [resolve-cb]
(js/setTimeout
(fn []
(resolve-cb value))
500))))
(p-def val-1 (defer-value 1))
(p-do (println val-1))
(p-def val-2 (defer-value (inc val-1)))
(p-do (println val-2))
(p-def val-3 (defer-value (inc val-2)))
(p-do (println val-3))
(https://gist.github.com/zharinov/e9536a50a6ef67fe4ac98ba12ad6b5e7)