Skip to content

Commit

Permalink
Add multi maps arg to set-handle-change
Browse files Browse the repository at this point in the history
  • Loading branch information
luciodale committed Jun 1, 2021
1 parent 043abeb commit 3e1cf63
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [2.4.1]
### Added
- set-handle-change takes a vector of maps vs one map

## [2.4.0]
### Added
- Add support for fieldarray drag and drop (only top level fieldarrays)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ As at this state you must be dying of curiosity, I will dive right into the impl
#### In Deps

```clojure
fork {:mvn/version "2.4.0"}
fork {:mvn/version "2.4.1"}
```

or
Expand Down
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject fork "2.4.0"
(defproject fork "2.4.1"
:description "Reagent & Re-Frame form library"
:url "https://github.com/luciodale/fork"
:license {:name "MIT"}
Expand Down
26 changes: 22 additions & 4 deletions src/fork/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,33 @@
path (conj vec-field-array-key idx input-key)]
(swap! state update :touched conj path)))

(defn set-handle-change
[{:keys [value path]} state]
(defn- set-handle-change-one
[deref-state {:keys [value path]}]
(let [path (vectorize-path path)
current-value (get-in @state (cons :values path))
current-value (get-in deref-state (cons :values path))
new-value (if (fn? value) (value current-value) value)
resolved-new-value (if (seq? new-value)
(doall new-value)
new-value)]
(swap! state assoc-in (cons :values path) resolved-new-value)))
(assoc-in deref-state (cons :values path) resolved-new-value)))

(defn set-handle-change
[params state]
(cond
(map? params)
(swap! state #(set-handle-change-one % params))

(sequential? params)
(swap! state
(fn [old-state]
(->> (remove nil? params)
(reduce
(fn [acc item]
(set-handle-change-one acc item))
old-state))))

:else (js/console.error "set-handle-change was called with the wrong
params. Provide either a map or a sequential collection")))

(defn set-handle-blur
[{:keys [value path]} state]
Expand Down

0 comments on commit 3e1cf63

Please sign in to comment.