diff --git a/src/zero/component.cljs b/src/zero/component.cljs index 33a64ec..a33a6af 100644 --- a/src/zero/component.cljs +++ b/src/zero/component.cljs @@ -193,6 +193,11 @@ Implements web components. Require this ns to enable them. (doseq [[k watchable] (:zero.core/bind props)] (when (some? watchable) (dom/unbind [watchable dom k]))) + (doseq [[k listener] (:zero.core/on props)] + (when (some? listener) + (if (instance? Signal k) + (sig/unlisten k [listener dom k]) + (dom/unlisten [listener dom k])))) (gobj/set dom dom/PROPS-SYM (dissoc props :zero.core/bind))) (doseq [child-dom (-> dom .-childNodes array-seq)] (prepare-dom-to-be-detached child-dom !instance-state)) diff --git a/src/zero/impl/signals.cljs b/src/zero/impl/signals.cljs index 288f9ce..f4dc63c 100644 --- a/src/zero/impl/signals.cljs +++ b/src/zero/impl/signals.cljs @@ -47,5 +47,5 @@ (defn unlisten [sig k] - (swap! !listeners dissoc-in [(.-key sig) k]) + (swap! !listeners dissoc-in [(.-key sig) k]) nil) \ No newline at end of file diff --git a/test/zero/browser/component_test.cljs b/test/zero/browser/component_test.cljs index d914cf8..7339548 100644 --- a/test/zero/browser/component_test.cljs +++ b/test/zero/browser/component_test.cljs @@ -106,7 +106,12 @@ (assert (= "FOO" (-> el .-shadowRoot .-firstChild .-innerText))) (reset! !atom "ZZZ")) (fn [^js/HTMLElement el] - (assert (= "FOO" (-> el .-shadowRoot .-firstChild .-innerText)))))) + (assert (= "FOO" (-> el .-shadowRoot .-firstChild .-innerText)))) + (fn [^js/HTMLElement el] + (set! (.-vdom el) [:div])) + (fn [_] + (assert (empty? @@(resolve 'zero.impl.dom/!binds))) + (assert (empty? @@(resolve 'zero.impl.dom/!bound-props)))))) (js/it "listens for events" (let [!invoked? (atom false)] @@ -119,8 +124,12 @@ ::z/on {:click #(reset! !invoked? true)}]])) (fn [^js/HTMLElement el] (-> el .-shadowRoot .-firstChild .click)) - (fn [^js/HTMLElement _el] - (assert (= true @!invoked?)))))) + (fn [_] + (assert (= true @!invoked?))) + (fn [^js/HTMLElement el] + (set! (.-vdom el) [:div])) + (fn [_] + (assert (empty? @@(resolve 'zero.impl.dom/!listener-aborters))))))) (js/it "listens for signals and receives correct context" (let [!signal-context (atom nil) @@ -132,10 +141,13 @@ [:root> [:button ::z/on {my-signal #(reset! !signal-context %)}]])) - (fn [^js/HTMLElement _el] + (fn [_] (my-signal)) (fn [^js/HTMLElement el] - (prn @!signal-context) (assert (= el (::z/host @!signal-context))) (assert (= (.-shadowRoot el) (::z/root @!signal-context))) - (assert (= (-> el .-shadowRoot .-firstChild) (::z/current @!signal-context)))))))) \ No newline at end of file + (assert (= (-> el .-shadowRoot .-firstChild) (::z/current @!signal-context)))) + (fn [^js/HTMLElement el] + (set! (.-vdom el) [:div])) + (fn [_] + (assert (empty? @@(resolve 'zero.impl.signals/!listeners)))))))) \ No newline at end of file