Skip to content

debounce toggles state when reacl-c.core/init is involved #15

@markusschlegel

Description

@markusschlegel

This code performs a 1 second debounce as I would expect:

(ns todomvc.core
  (:require [reacl-c.main :as main]
            [reacl-c.dom :as dom :include-macros true]
            [reacl-c.core :as c :include-macros true]
            [reacl-c-basics.debounce :as debounce]))

(defn init []
  (main/run
    (.getElementById js/document "app")

    (c/fragment
     (c/dynamic pr-str)
     (debounce/debounce-delay 1000 (c/with-state-as st
                                     (dom/div

                                      ;; add this line to notice the flip-flop behaviour:
                                      ;; (c/init (c/return))

                                      (dom/button {:onclick not}
                                                  (pr-str st))))))

    {:initial-state false}
    ))

When you uncomment the (c/init (c/return)) line, the behaviour changes: Now when you click the button, the state toggles between true and false every second.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions