From e411ab59a26b38ecdf45fb87de4fcfe8ef7d1b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20NOEL?= Date: Wed, 9 Oct 2024 11:48:49 +0200 Subject: [PATCH] do not dispose convicted outputs --- src/hyperfiddle/electric/impl/runtime3.cljc | 3 +- test/hyperfiddle/electric3_test.cljc | 35 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/hyperfiddle/electric/impl/runtime3.cljc b/src/hyperfiddle/electric/impl/runtime3.cljc index c982b4838..79d8e86b3 100644 --- a/src/hyperfiddle/electric/impl/runtime3.cljc +++ b/src/hyperfiddle/electric/impl/runtime3.cljc @@ -1023,7 +1023,8 @@ T T T -> (EXPR T) (do (aset output output-slot-requested false) (port-deps input-down nil port) (when (zero? (aget output output-slot-refcount)) - (output-dispose output))) + (when (identical? output (aget output output-slot-convicted)) + (output-dispose output)))) (do (aset output output-slot-requested true) (port-deps input-up nil port))) remote)) diff --git a/test/hyperfiddle/electric3_test.cljc b/test/hyperfiddle/electric3_test.cljc index 02dc07447..6f710b829 100644 --- a/test/hyperfiddle/electric3_test.cljc +++ b/test/hyperfiddle/electric3_test.cljc @@ -2371,3 +2371,38 @@ (tests (with ((l/single {} (tap (.fooBar (js/Object.)))) tap (fn [_] (tap :error))) % := :error)))) + +(tests + + (let [!x (atom 0) + !y (atom true) + !z (atom true) + !clocks (atom {}) + clock (fn [k] + (m/observe + (fn [!] + (swap! !clocks assoc k !) + #(swap! !clocks dissoc k)))) + tick (fn [k] ((@!clocks k) nil))] + ((l/local {::lang/client-clock [(clock :client-read) (clock :client-write)] + ::lang/server-clock [(clock :server-read) (clock :server-write)]} + (let [x (e/watch !x)] + (when (e/watch !y) + (e/server [(identity x) + (when (e/watch !z) x)])))) + tap tap) + (tick :client-write) + (tick :server-read) + (tick :server-write) + (swap! !z not) + (tick :server-write) + (swap! !y not) + (tick :client-write) + (tick :client-read) + (tick :client-read) + (tick :server-read) + (tick :server-write) + (tick :client-read) + (tick :client-write) + (tap :done) + % := :done)) \ No newline at end of file