Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nested objects #29

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Joanata
Copy link
Contributor

@Joanata Joanata commented Jun 26, 2020

This PR adds the support for nested objects.

Issue #28

@Joanata Joanata force-pushed the feature/support-for-nested-objects branch from 9e72a00 to e517ac3 Compare June 26, 2020 17:11
error: errors?.[field] ?? null,
meta: meta?.[field] ?? {},
value: values?.[field]
error: errors ? get(errors, field) : null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With get there's no need to check if errors exists. You can also pass the fallback value as the third argument.

Suggested change
error: errors ? get(errors, field) : null,
error: get(errors, field, null),

Please do the same in the two lines below.

@@ -99,13 +99,13 @@ const valuesReducer = (state, action) => {
case actionTypes.SET_FIELD_VALUE:
return {
...state,
[payload.field]: payload.value
...set(state, payload.field, payload.value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set mutates the object you pass as the first argument, so this mutates the previous state, which should be avoided. Instead, please pass an empty object as the first argument:

Suggested change
...set(state, payload.field, payload.value)
...set({}, payload.field, payload.value)

Please do the same on other set calls you have.


function getNestedKeys(state: Object, allKeys: Array<string>): Array<string> {
return Object.keys(state).reduce((acc, key) => {
if (fieldMetaKeys.includes(key)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this... What if you have a field in the form named active?

What do you think about keeping the meta object as a flat object with keys with dots? Like this:

meta: {
  'foo.bar': {
    active: false,
    // etc
  }
}

Let's discuss this on Monday, ok?

@Joanata Joanata force-pushed the feature/support-for-nested-objects branch from e517ac3 to 0077ce1 Compare June 29, 2020 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants