Skip to content

Commit 1c644e9

Browse files
author
awb99
committed
option-path can be a vector
1 parent 80ad8a7 commit 1c644e9

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

demo/src/demo/page/options.cljs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
:pet :hamster
1414
; bool
1515
:run-parallel true
16-
:debug? false
16+
:environment {:enabled true}
1717
; string
1818
:search ""
1919
; view
@@ -38,8 +38,8 @@
3838
:name "RunParallel?"
3939
:spec :bool
4040
:class "pt-0 px-2 py-1 placeholder-gray-400 text-gray-700 relative bg-white rounded text-sm border border-gray-400 outline-none focus:outline-none focus:shadow-outline"}
41-
{:path :debug?
42-
:name "DebugMode"
41+
{:path [:environment :enabled]
42+
:name "EnvEnabled?"
4343
:spec :bool}
4444
{:path :search
4545
:name "SearchBox"

resources/ext/options.edn

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
{:name "options"
22
; build
33
:lazy false
4-
54
:cljs-namespace [options.core
65
options.edit]
7-
86
:cljs-ns-bindings {'options.core {'options-ui options.core/options-ui}
9-
'options.editr {'bool options.edit/bool
10-
'button options.edit/button
11-
'select options.edit/select
12-
'string options.edit/string
13-
'view options.edit/view}}
14-
7+
'options.edit {'bool options.edit/bool
8+
'button options.edit/button
9+
'select options.edit/select
10+
'string options.edit/string
11+
'view options.edit/view}}
1512
; runtime
16-
1713
:theme {:available {:options {true ["options/options.css"]}}
1814
:current {:options true}}
1915
;

src/options/core.cljs

+26-10
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,33 @@
3333
[:span name] ; <label for= "pet-select" >Choose a pet:</label>
3434
(get-editor-fn config current-val)]))
3535

36+
(defn get-value [state path]
37+
(cond
38+
(keyword? path)
39+
(path @state)
40+
41+
(vector? path)
42+
(get-in @state path)
43+
44+
:else
45+
nil))
46+
47+
(defn set-value [state path v]
48+
(println "set-value path: " path " value: " v)
49+
(cond
50+
(keyword? path)
51+
(swap! state assoc path v)
52+
53+
(vector? path)
54+
(swap! state assoc-in path v)
55+
56+
:else
57+
nil))
58+
3659
(defn create-edit-element [state options]
37-
(let [kw (:path options)
38-
set-fn (fn [v]
39-
(when kw
40-
(println "setting state for kw: " kw " to val: " v)
41-
(swap! state assoc kw v)))]
42-
[edit-element {:set-fn set-fn
43-
:options options}
44-
(if kw
45-
(kw @state)
46-
nil)]))
60+
[edit-element {:set-fn #(set-value state (:path options) %)
61+
:options options}
62+
(get-value state (:path options))])
4763

4864
(defn options-ui [{:keys [class style] :as styling} ; styling
4965
{:keys [current state options]

0 commit comments

Comments
 (0)