Skip to content

Commit

Permalink
Add :keywordize-top-level-keys prop
Browse files Browse the repository at this point in the history
  • Loading branch information
luciodale committed Mar 1, 2021
1 parent bed9ebd commit a9c37bc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [2.2.6]
### Added
- `:keywordize-top-level-keys` to main props to only keywordize top-level-key values

## [2.2.5]
### Added
- `state` to main props to allow users to pass their own ratoms
Expand Down
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -33,7 +33,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.2.5"}
fork {:mvn/version "2.2.6"}
```

or
Expand Down Expand Up @@ -184,6 +184,8 @@ If some parts look a bit obscure, the will be explained thoroughly in the follow

`:keywordize-keys` allows you to work with keywords instead of strings. - Boolean

`:keywordize-top-level-keys` allows you to work with top level keywords instead of strings. - Boolean

`:prevent-default?` does not automatically send your form to the server on submit. - Boolean

`:clean-on-unmount?` resets the state when your component is unmounted. (Useful when used with re-frame). - Boolean
Expand Down
2 changes: 1 addition & 1 deletion project.clj
@@ -1,4 +1,4 @@
(defproject fork "2.2.5"
(defproject fork "2.2.6"
:description "Reagent & Re-Frame form library"
:url "https://github.com/luciodale/fork"
:license {:name "MIT"}
Expand Down
6 changes: 5 additions & 1 deletion src/fork/core.cljs
Expand Up @@ -16,11 +16,15 @@
(defn initialize-state
[props]
(let [kw? (:keywordize-keys props)
only-top-level-kw? (:keywordize-top-level-keys props)
values (or (merge (:initial-values props)
(:initial-touched props))
{})
initialized-state {:keywordize-keys (:keywordize-keys props)
:values (if kw? (walk/keywordize-keys values) values)
:values (cond
kw? (walk/keywordize-keys values)
only-top-level-kw? (into {} (mapv (fn [k v] [(keyword k) v]) values))
:else values)
;; TODO - support nested initial-touched keys
:touched (into #{} (map (if kw? keyword identity)
(keys (:initial-touched props))))}]
Expand Down

0 comments on commit a9c37bc

Please sign in to comment.