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

Update omits empty object #29

Closed
suevalov opened this issue Aug 18, 2015 · 2 comments
Closed

Update omits empty object #29

suevalov opened this issue Aug 18, 2015 · 2 comments

Comments

@suevalov
Copy link

I have the following situation:

const store = {
   widgets: {
     1: { ... },
     2: { ... }
   }
}

Each widget has the following structure:

const widget = {
   id: number,
   title: string,
   displayParameters: Object
   ...
}

Sometimes displayParameters object may be empty.

So, the problem is that if displayParameters is an empty object, it disappears after updeep.

const newWidget = {
   id: 123,
   title: 'new one',
   displayParameters: {}
};
store = updeep({
  widgets: {
    [newWidget.id]: newWidget
  }
}, store)

/*
store: {
 widgets: {
   ...
   123: {
     id: 123,
     title: 'new one' 
   }
  }
}
*/

I have checked this issue and wrote the test - the same result. Not sure if it's correct behaviour.

it('it should not omit empty object', () => {
    const store = {
      widgets: {
        1: {
          title: '123',
          displayParams: {
            index: 1
          }
        }
      }
    };

    const result = u({
      widgets: {
        123: {
          title: 'new widget',
          displayParams: {}
        }
      }
    }, store);

    expect(result).toEqual({
      widgets: {
        1: {
          title: '123',
          displayParams: {
            index: 1
          }
        },
        123: {
          title: 'new widget',
          displayParams: {}  // test is failed here
        }
      }
    });
  });
@aaronjensen
Copy link
Member

Thanks for the report and the test. This is fixed in 0.7.1. The behavior was actually intentional, but it's overly pedantic and surprising, I think.

@suevalov
Copy link
Author

Wow, it was quick. Thanks!

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

No branches or pull requests

2 participants