Skip to content

Commit

Permalink
option-path can be a vector
Browse files Browse the repository at this point in the history
  • Loading branch information
awb99 committed Mar 7, 2024
1 parent 80ad8a7 commit 1c644e9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
6 changes: 3 additions & 3 deletions demo/src/demo/page/options.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
:pet :hamster
; bool
:run-parallel true
:debug? false
:environment {:enabled true}
; string
:search ""
; view
Expand All @@ -38,8 +38,8 @@
:name "RunParallel?"
:spec :bool
: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"}
{:path :debug?
:name "DebugMode"
{:path [:environment :enabled]
:name "EnvEnabled?"
:spec :bool}
{:path :search
:name "SearchBox"
Expand Down
14 changes: 5 additions & 9 deletions resources/ext/options.edn
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
{:name "options"
; build
:lazy false

:cljs-namespace [options.core
options.edit]

:cljs-ns-bindings {'options.core {'options-ui options.core/options-ui}
'options.editr {'bool options.edit/bool
'button options.edit/button
'select options.edit/select
'string options.edit/string
'view options.edit/view}}

'options.edit {'bool options.edit/bool
'button options.edit/button
'select options.edit/select
'string options.edit/string
'view options.edit/view}}
; runtime

:theme {:available {:options {true ["options/options.css"]}}
:current {:options true}}
;
Expand Down
36 changes: 26 additions & 10 deletions src/options/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,33 @@
[:span name] ; <label for= "pet-select" >Choose a pet:</label>
(get-editor-fn config current-val)]))

(defn get-value [state path]
(cond
(keyword? path)
(path @state)

(vector? path)
(get-in @state path)

:else
nil))

(defn set-value [state path v]
(println "set-value path: " path " value: " v)
(cond
(keyword? path)
(swap! state assoc path v)

(vector? path)
(swap! state assoc-in path v)

:else
nil))

(defn create-edit-element [state options]
(let [kw (:path options)
set-fn (fn [v]
(when kw
(println "setting state for kw: " kw " to val: " v)
(swap! state assoc kw v)))]
[edit-element {:set-fn set-fn
:options options}
(if kw
(kw @state)
nil)]))
[edit-element {:set-fn #(set-value state (:path options) %)
:options options}
(get-value state (:path options))])

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

0 comments on commit 1c644e9

Please sign in to comment.