diff --git a/src/zero/component.cljs b/src/zero/component.cljs index 23674c3..ccea34c 100644 --- a/src/zero/component.cljs +++ b/src/zero/component.cljs @@ -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 @@ -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 #{}) @@ -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] diff --git a/src/zero/dom.cljs b/src/zero/dom.cljs index bdbaa03..c4e6514 100644 --- a/src/zero/dom.cljs +++ b/src/zero/dom.cljs @@ -4,6 +4,7 @@ [zero.impl.base :refer [IDisposable dispose!]] [zero.config :as config] [zero.core :refer [<< < (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