-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
awb99
committed
Jul 15, 2024
1 parent
29f751f
commit d87d308
Showing
5 changed files
with
100 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(ns demo.ui) | ||
|
||
|
||
(defn a-flow-ui [v] | ||
[:div | ||
"current a-flow value: " | ||
(pr-str v)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
(ns re-flow.ui | ||
(:require | ||
[reagent.core :as r] | ||
[promesa.core :as p] | ||
[webly.spa.resolve :refer [get-resolver]])) | ||
|
||
(defn log [& args] | ||
(.log js/console (apply str args))) | ||
|
||
(defn loading-ui [s] | ||
[:p "loading: " (pr-str s)]) | ||
|
||
(defn load-error-ui [s] | ||
[:p "render load error: " (pr-str s)]) | ||
|
||
(defn create-loader-ui [load-atom s] | ||
(fn [& args] | ||
(fn [& args] | ||
(let [{:keys [status fun]} @load-atom] | ||
(case status | ||
:loading [loading-ui s] | ||
:error [load-error-ui s] | ||
:loaded (into [fun] args) | ||
[loading-ui s]))))) | ||
|
||
(defn update-atom [load-a p] | ||
(-> p | ||
(.then (fn [f] | ||
(log "get-render-fn resolved fun: " f) | ||
(if f | ||
(swap! load-a assoc :status :loaded :fun f) | ||
(swap! load-a assoc :status :error)))) | ||
(.catch (fn [d] | ||
(log "get-render-fn: require result failure!") | ||
(swap! load-a assoc :status :error))))) | ||
|
||
(defn get-render-fn [s] | ||
(let [load-a (r/atom {:status :loading}) | ||
resolve-fn (get-resolver) | ||
fun (resolve-fn s)] | ||
(if (p/promise? fun) | ||
(update-atom load-a fun) | ||
(swap! load-a assoc :status :loaded :fun fun)) | ||
(create-loader-ui load-a s))) | ||
|
||
|
||
(defn show-data [s v] | ||
(fn [s v] | ||
(log "show-data symbol: " s " val: " v) | ||
(let [render-fn (get-render-fn s)] | ||
(if render-fn | ||
[render-fn v] | ||
[:p "unknown render-fn: " (str s)])))) | ||
|
||
|
||
|