Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(ns whatever.sub-test
(:require [reagent.core :as r]
[reagent.ratom :as ratom]
[re-frame.core :as rf]))
(def invalidate-form
{:before identity
:after (fn [{{:keys [:db]} :effects :as ctx}]
(assoc-in ctx [:effects :db :test-changed] true))}))
(fn [db] (:test db)))
(fn [db [_ newval]] (assoc db :test newval)))
(fn [db [_ newval]]
(assoc db :test-changed newval)))
(fn [db _] (:test-changed db)))
(fn [db [_ newd]]
(assoc-in db [:test :b 1 :d] newd)))
(defn re-frame-idiomatic-games []
(let [changed (rf/subscribe [:test-changed])
test (rf/subscribe [:test])]
[:button {:on-click #(rf/dispatch [:set-test {:a 1 :b [{:c 3} {:d 4}]}])}
"Set initial state"]
[:button {:on-click #(rf/dispatch [:change-d (rand-int 10)])}
"Change field in :test randomly"]
[:button {:on-click #(rf/dispatch [:set-test-changed false])}
"Reset :test-changed"]
[:div ":test " (str @test)]
[:div ":test-changed " (str @changed)]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment