From 6c345db29e45a64b144ab0ddda007c694e9533b7 Mon Sep 17 00:00:00 2001 From: Dan Holmsand Date: Mon, 31 Aug 2015 10:39:17 +0200 Subject: [PATCH] Now almost working --- src/reagent/ratom.cljs | 30 +++++++++++++++++++----------- test/reagenttest/testcursor.cljs | 2 +- test/reagenttest/testratom.cljs | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/reagent/ratom.cljs b/src/reagent/ratom.cljs index 1621492..ad6d3b1 100644 --- a/src/reagent/ratom.cljs +++ b/src/reagent/ratom.cljs @@ -195,7 +195,8 @@ (defprotocol IComputedImpl (-update-watching [this derefed]) (-handle-change [k sender oldval newval]) - (-peek-at [this])) + (-peek-at [this]) + (-check-clean [this])) (def clean 0) (def maybe-dirty 1) @@ -250,8 +251,12 @@ (if (identical? oldval newval) maybe-dirty is-dirty))) (if auto-run - (when (> dirty? clean) - ((or auto-run run) this)) + (do + ;; FIXME: is this correct? + (binding [*ratom-context* this] + (-check-clean this)) + (when (> dirty? clean) + ((or auto-run run) this))) (-notify-watches this state state))) ;; (when (and active? (not (identical? oldval newval))) ;; (set! dirty? is-dirty) @@ -273,6 +278,16 @@ (binding [*ratom-context* nil] (-deref this)))) + (-check-clean [this] + (when (== dirty? maybe-dirty) + (let [oldauto auto-run] + (set! auto-run nil) + (doseq [w watching] + (-deref w)) + (set! auto-run oldauto)) + (when (== dirty? maybe-dirty) + (set! dirty? clean)))) + IRunnable (run [this] (let [oldstate state @@ -290,14 +305,7 @@ IDeref (-deref [this] - (when (== dirty? maybe-dirty) - (let [oldauto auto-run] - (set! auto-run nil) - (doseq [w watching] - (-deref w)) - (set! auto-run oldauto)) - (when (== dirty? maybe-dirty) - (set! dirty? clean))) + (-check-clean this) (if (or auto-run (some? *ratom-context*)) (do (notify-deref-watcher! this) diff --git a/test/reagenttest/testcursor.cljs b/test/reagenttest/testcursor.cljs index a3d14de..5c08736 100644 --- a/test/reagenttest/testcursor.cljs +++ b/test/reagenttest/testcursor.cljs @@ -11,7 +11,7 @@ (rv/running)) (defn dispose [v] (rv/dispose! v)) -(def testite 1) +(def testite 10) (deftest basic-cursor (let [runs (running) diff --git a/test/reagenttest/testratom.cljs b/test/reagenttest/testratom.cljs index 2258e0d..0f91a40 100644 --- a/test/reagenttest/testratom.cljs +++ b/test/reagenttest/testratom.cljs @@ -8,7 +8,7 @@ (set! rv/debug true) (rv/running)) -(def testite 1) +(def testite 10) (defn dispose [v] (rv/dispose! v))