Skip to content

Commit

Permalink
bug fixes + add errors to default CDF operators
Browse files Browse the repository at this point in the history
  • Loading branch information
raystubbs committed Sep 6, 2024
1 parent 0d02205 commit d84af90
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
13 changes: 9 additions & 4 deletions src/zero/cdf.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[zero.impl.base :refer [str-writer str-writer->str write]])
#?(:clj
(:import
[java.util ArrayList Date])))
[java.util ArrayList Date])))

#?(:clj (defn- mut-list [] (ArrayList.))
:cljs (defn- mut-list [] #js[]))
Expand Down Expand Up @@ -71,7 +71,7 @@

\e
(case
:exponent
:exponent
(throw (ex-info "found extra 'e' in number" {:idx i :char c})))

(\space \newline \return \tab \[ \] \{ \} \( \) \`)
Expand Down Expand Up @@ -223,6 +223,7 @@
'bnd z/bnd
'<< z/<<
'set (fn [& xs] (set xs))
'err (fn [& args] (ex-info (first args) (second args)))
'inst #?(:cljs #(js/Date. %) :clj #(Date. ^String %))})

(defn read-str
Expand Down Expand Up @@ -280,7 +281,11 @@
(list 'inst #?(:cljs (.toISOString x) :clj (.toString x)))

:else
x))
(if-some [msg (ex-message x)]
(if-some [data (ex-data x)]
(list 'err msg data)
(list 'err msg))
x)))

(defn- max-quotes-count
[s]
Expand Down Expand Up @@ -399,4 +404,4 @@
(defn write-str
[x & {:as opts}]
(let [w (str-writer)]
(write-val w x (merge {:mapper default-mapper :top? true} opts))))
(write-val w x (merge {:mapper default-mapper :top? true} opts))))
34 changes: 24 additions & 10 deletions src/zero/dom.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@
(fn [^js target]
(apply (gobj/get target (name method-name)) args)))))

(defn- set-field!
[target field-name value]
(-> (js/Promise.resolve target)
(.then
(fn [^js target]
(gobj/set target (name field-name) value)))))

(defn listen-view
[!db {:keys [sel evt] action :act :as props {!mut :mut} :state}]
(let [action
Expand Down Expand Up @@ -177,7 +184,7 @@
(catch :default ex
(reject ex)))))))

(defn select-one
(defn inj-select-one
[{^js/Node root ::z/root !db ::z/db}
selector
& {:keys [deep? delay from]}]
Expand All @@ -195,7 +202,7 @@
(-> ^js/Promise from (.then #(delayed !db delay select-fn %)))
(delayed !db delay select-fn (or from root)))))

(defn select-all
(defn- inj-select-all
[{^js/Node root ::z/root !db ::z/db}
selector
& {:keys [deep? delay from]}]
Expand All @@ -213,7 +220,7 @@
(-> ^js/Promise from (.then #(delayed !db delay select-fn %)))
(delayed !db delay select-fn (or from root)))))

(defn select-closest
(defn- inj-select-closest
[{^js/Node root ::z/root ^js/Node current ::z/current !db ::z/db}
selector
& {:keys [breach? delay from]}]
Expand All @@ -230,26 +237,33 @@
(-> ^js/Promise from (.then #(delayed !db delay select-fn root %)))
(delayed !db delay select-fn root (or from current)))))

(defn shadow
(defn- inj-shadow
[_ target]
(if (instance? js/Promise target)
(-> target (.then #(.-shadowRoot ^js target)))
(.-shadowRoot ^js target)))

(defn- inj-field
[_ ^js target field-name]
(if-not (instance? js/Promise target)
(gobj/get target (name field-name))
(.then target (fn [^js target] (gobj/get target (name field-name))))))

(defn install!
[!db]
(zc/reg-effects !db
::patch-internal-state patch-internal-state!
::set-internal-state set-internal-state
::dispatch (vary-meta dispatch! assoc ::z/contextual true)
::invoke invoke!)
::invoke invoke!
::set-field set-field!)

(zc/reg-injections !db
::select-one select-one
::select-all select-all
::select-closest select-closest
::shadow shadow
::field (fn [target field-name] (gobj/get target field-name)))
::select-one inj-select-one
::select-all inj-select-all
::select-closest inj-select-closest
::shadow inj-shadow
::field inj-field)

(zc/reg-components !db
::echo
Expand Down
2 changes: 1 addition & 1 deletion src/zero/tools/portfolio.cljc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns zero.tools.portfolio
#?(:cljs (:require-macros net.xledger.ui.tooling.portfolio))
#?(:cljs (:require-macros zero.tools.portfolio))
(:require
#?(:clj [portfolio.core :as portfolio])
[subzero.plugins.html :as html]
Expand Down

0 comments on commit d84af90

Please sign in to comment.