Coder Social home page Coder Social logo

State changes not picked up about citrus HOT 6 CLOSED

clj-commons avatar clj-commons commented on September 25, 2024
State changes not picked up

from citrus.

Comments (6)

gmp26 avatar gmp26 commented on September 25, 2024

Just tested by patching the example counter with:

[:button {:on-click #(doseq [i (range 10)] (citrus/dispatch! r :counter :inc))} "+10"]

and yes, the counter only increments by 1.

Whereas:

[:button {:on-click #(doseq [i (range 10)] (citrus/dispatch-sync! r :counter :inc))} "+10"]

increments by 10.

from citrus.

gmp26 avatar gmp26 commented on September 25, 2024

OK, I'm now of the opinion this is the behaviour we should expect for the asynchronous case as forcing a wait on state handling before enqueuing another event would be equivalent to synchronous behaviour.

from citrus.

roman01la avatar roman01la commented on September 25, 2024

This is definitely a bug. Async events are batched and executed asynchronously, but this should not change the behavior. I’ll look into this.

from citrus.

mjmeintjes avatar mjmeintjes commented on September 25, 2024

Here's what I'm using for now:

(r/dispatch! [this cname event args]
    (queue-effects!
     queue
     [cname #((get controllers cname) event args (get % cname))])

    (schedule-update!
     batched-updates
     scheduled?
     (fn []
       (let [effects (into [] @queue)]
         (clear-queue! queue)
         (let [[curr-state handlers]
               (reduce
                (fn [[curr-state handlers] [cname ctrl]]
                  (let [effects (ctrl curr-state)]
                    [(if-let [s (:state effects)]
                       (assoc curr-state cname s)
                       curr-state)
                     (concat handlers (->> (dissoc effects :state)
                                           (filter (comp seq second))))]))
                [@state []]
                effects)]
           (reset! state curr-state)
           (m/doseq [[id effect] handlers]
             (when-let [handler (get effect-handlers id)]
               (handler this cname effect))))))))

I can make a PR if you are interested.

from citrus.

gmp26 avatar gmp26 commented on September 25, 2024

@roman01la - yes - much easier to think about that way! Code from @mjmeintjes fixes my test case.

from citrus.

roman01la avatar roman01la commented on September 25, 2024

Just published a fix in 3.0.1. @mjmeintjes thank you for that code sample

from citrus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.