Skip to content

Commit

Permalink
Small fixes and feature experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
raystubbs committed May 17, 2024
1 parent d03a868 commit d670a70
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/zero/component.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Implements web components. Require this ns to enable them.
(def ^:private JS-UNDEFINED (js* "undefined"))
(def ^:private RENDER-ORDER-SYM (js/Symbol "zRenderOrder"))

(def before-render-sig (Signal. ::before-render))
(def after-render-sig (Signal. ::after-render))

(defn- default-ns
[tag]
(case tag
Expand Down Expand Up @@ -422,6 +425,7 @@ Implements web components. Require this ns to enable them.
(defn- render
[]
(reset! !render-frame-id nil)
(before-render-sig)
(while (seq @!dirty)
(let [batch @!dirty]
(reset! !dirty #{})
Expand Down Expand Up @@ -472,7 +476,8 @@ Implements web components. Require this ns to enable them.
(when (contains? observed-events event-type)
(.dispatchEvent shadow (js/Event. event-type #js{:bubbles false})))
(when (contains? observed-events "render")
(.dispatchEvent shadow (js/Event. "render" #js{:bubbles false}))))))))))))
(.dispatchEvent shadow (js/Event. "render" #js{:bubbles false})))))))))))
(after-render-sig))

(defn- request-render
[^js/Node dom]
Expand Down
10 changes: 9 additions & 1 deletion src/zero/dom.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[zero.impl.base :refer [IDisposable dispose!]]
[zero.config :as config]
[zero.core :refer [<< <<ctx act]:as z]
[zero.extras.db :as db] ;; not supposed to use 'extras' in core modules, big changes coming, this is temporary
[clojure.string :as str]
[goog.object :as gobj]))

Expand Down Expand Up @@ -31,12 +32,19 @@
(reset! !state new-state)
(throw (ex-info "No internal state available on given DOM node" {:dom dom}))))

(defn patch-internal-state
[^js/Node dom patch]
(if-let [!state (gobj/get dom INTERNAL-STATE-SYM)]
(swap! !state (comp first db/apply-patch) patch)
(throw (ex-info "No internal state available on given DOM node" {:dom dom}))))

(config/reg-effects
::listen listen
::unlisten unlisten
::bind bind
::unbind unbind
::set-internal-state set-internal-state)
::set-internal-state set-internal-state
::patch-internal-state patch-internal-state)

(config/reg-injections
::select-doms
Expand Down
21 changes: 20 additions & 1 deletion src/zero/impl/actions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[goog.object :as gobj]
[goog :refer [DEBUG]]
[zero.config :as config]
[zero.impl.signals :as sig]
[zero.logger :as log]))

(defonce Action (js* "
Expand Down Expand Up @@ -106,7 +107,25 @@
(actually-perform!)

:default
(js/setTimeout actually-perform!))
(js/setTimeout actually-perform!)

:after-render
(when-let [after-render-sig (some-> (resolve 'zero.component/after-render-sig) deref)]
(let [k (gensym)]
(sig/listen after-render-sig k
(fn []
(sig/unlisten after-render-sig k)
(actually-perform!))
nil)))

:before-render
(when-let [before-render-sig (some-> (resolve 'zero.component/before-render-sig) deref)]
(let [k (gensym)]
(sig/listen before-render-sig k
(fn []
(sig/unlisten before-render-sig k)
(actually-perform!))
nil))))
nil)))

IEquiv
Expand Down

0 comments on commit d670a70

Please sign in to comment.