(ns microtables-frontend.events (:require [re-frame.core :as re-frame] [microtables-frontend.db :as db])) (re-frame/reg-event-db ::initialize-db (fn [_ _] db/default-db)) (re-frame/reg-event-db ::edit-cell-value (fn [db [_ c r existing-datum value]] (if (nil? existing-datum) (assoc db :table-data (conj (:table-data db) {:row r :col c :value value :dirty true})) (assoc db :table-data (map #(if (and (= r (:row %)) (= c (:col %))) (assoc (assoc % :dirty true) :value value) %) (:table-data db))))))