Skip to content

Commit

Permalink
[i/items] orphaned item-ps doesn't step on cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurC committed Sep 10, 2024
1 parent 66fa8f4 commit 711a724
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/hyperfiddle/incseq/items_eager_impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
(#?(:clj invoke :cljs -invoke) [this]
(remove-item-ps item this)
(let [cancelled? (a/getset a -cancelled true)]
(when (not (or (a/getset a -stepped true) cancelled?)) (step))))
(when-not (or (a/getset a -stepped true) cancelled? (= this (a/get a -cache))) (step))))
(#?(:clj invoke :cljs -invoke) [_ v]
(when-not (or (= v (a/getset a -cache v)) (a/getset a -stepped true))
(step)))
Expand Down
20 changes: 20 additions & 0 deletions test/hyperfiddle/incseq/items_eager_impl_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,26 @@
_ (q ::none)
_ (t/is (= ::none (q)))]))

(t/deftest orphaned-item-ps-doesnt-step-on-cancel
(let [q (->mq)
_ (q (assoc (d/empty-diff 1) :grow 1 :change {0 :foo})) ; what input will return on transfer
items (spawn-ps q)
[in-step _in-done] (q)
_ (t/is (= :items-step (q)))
diff @items
_ (t/is (= (assoc (d/empty-diff 1) :grow 1) (assoc diff :change {})))
item0 ((-> diff :change (get 0)) #(q :item0-step) #(q :item0-done))
_ (t/is (= :item0-step (q)))
_ (t/is (= :foo @item0))
_ (q (assoc (d/empty-diff 1) :shrink 1))
_ (in-step)
_ (t/is (= :item0-done (q)))
_ (t/is (= :items-step (q)))
_ (t/is (= (assoc (d/empty-diff 1) :shrink 1) @items))
_ (item0)
_ (q ::none)
_ (t/is (= ::none (q)))]))

;; missing tests
;; - double transfer (optional)
;; - item-ps
Expand Down

0 comments on commit 711a724

Please sign in to comment.