File tree Expand file tree Collapse file tree 2 files changed +16
-9
lines changed
Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change 22
33## Added
44
5- ## Fixed
6-
7- ## Changed
5+ - add ` reinit! ` (since ` reset! ` was taken), to reset a form to its initial state
86
97# 0.1.4 (2023-09-06 / 85cc0b6)
108
119## Added
1210
13- - ` with-form ` / ` deform `
11+ - ` with-form ` / ` deform `
Original file line number Diff line number Diff line change 1818 formdef)]
1919 [@p form]))
2020
21+ (defprotocol IMorf
22+ (reinit! [r]))
23+
2124(defn- compute-bindings [binding form placeholders init]
2225 (let [lookup (gensym " lookup" )]
2326 (conj (into []
2427 (mapcat (fn [p]
25- [p `(reagent.core/atom ~(get init p))])
28+ [p `(let [init# ~(get init p)]
29+ (cljs.core/specify! (reagent.core/atom init#)
30+ IMorf
31+ (~'reinit! [this#] (reset! this# init#))))])
2632 placeholders))
33+
2734 lookup
2835 (zipmap
2936 (map (comp keyword str) placeholders)
3239 binding
3340 `(cljs.core/specify! (reagent.core/reaction ~form)
3441 cljs.core/ILookup
35-
3642 (~'-lookup
3743 ([_# k#] (~'-lookup ~lookup k#))
38- ([_# k# not-found#] (~'-lookup ~lookup k# not-found#)))))))
44+ ([_# k# not-found#] (~'-lookup ~lookup k# not-found#)))
45+ IMorf
46+ (~'reinit! [_#]
47+ (doseq [p# ~(into [] placeholders)]
48+ (reinit! p#)))))))
3949
4050#?(:clj
4151 (defmacro with-form [[binding formdef & {:keys [init]}] & body]
4959 (let [[placeholders form] (find-placeholders formdef)]
5060 `(do
5161 ~@(for [[bind form] (partition 2 (compute-bindings binding form placeholders init))]
52- `(def ~bind ~form))
53- ))))
62+ `(def ~bind ~form))))))
You can’t perform that action at this time.
0 commit comments