Skip to content

Commit 7e6fc1f

Browse files
author
awb99
committed
bugfix option-ui2
1 parent 133bf7d commit 7e6fc1f

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/options/core.cljs

+14-11
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
(defn get-editor [t]
2424
(or (get @editors t) editor-view))
2525

26-
(defn create-edit-element [{:keys [set-fn get-fn]} {:keys [path name type] :as options}]
26+
(defn create-edit-element [{:keys [state set-fn get-fn]} {:keys [path name type] :as options}]
2727
(let [editor (get-editor type)]
2828
(if (= type :label)
2929
; label only
@@ -39,24 +39,27 @@
3939
:display "inline-block"}}
4040

4141
name] ; <label for= "pet-select" >Choose a pet:</label>
42-
[editor {:set-fn (partial set-fn path)
42+
[editor {:set-fn (partial set-fn state path)
4343
:options options}
44-
(get-fn path)]])))
44+
(get-fn @state path)]])))
4545

4646
(defn options-ui2 [{:keys [class style
4747
edit
4848
state
4949
set-fn
50-
get-fn]
51-
:or {set-fn (fn [path v]
52-
;(println "setting " path " to: " v)
53-
(swap! state assoc path v))
54-
get-fn (fn [path]
55-
(get @state path))}}]
50+
get-fn]}]
51+
(let [set-fn (or set-fn
52+
(fn [path v]
53+
;(println "setting " path " to: " v)
54+
(swap! state assoc path v)))
55+
get-fn (or get-fn
56+
(fn [state-val path]
57+
(get state-val path)))]
5658
(into [:div {:style style
5759
:class class}]
58-
(map #(create-edit-element {:set-fn set-fn
59-
:get-fn get-fn} %) edit)))
60+
(map #(create-edit-element {:state state
61+
:set-fn set-fn
62+
:get-fn get-fn} %) edit))))
6063

6164
(defn options-ui [{:keys [class style]} ; styling
6265
{:keys [current state options]

0 commit comments

Comments
 (0)