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

merge doesn't work with objects that don't have a prototype. #39

Closed
ngbrown opened this issue Oct 31, 2018 · 2 comments
Closed

merge doesn't work with objects that don't have a prototype. #39

ngbrown opened this issue Oct 31, 2018 · 2 comments

Comments

@ngbrown
Copy link

ngbrown commented Oct 31, 2018

The package query-string is generating objects that have no prototype by using Object.create(null).

I want to deep merge with those objects, but icepick is not thinking they are objects because the isObject test check for prototype.

import {merge} from 'icepick';

// build object like query-string does
let query = Object.create(null);
query['q'] = 'search-term';
const route = {url: './', query: query};

// prepare action for history
const nextPage = merge(route, {query: {page: 2}});

// what I expect to be the result
assert.same(nextPage, {url: './', query: {q: 'search-term', page: 2}});
@aearly
Copy link
Owner

aearly commented Nov 1, 2018

Ah fascinating! Looks like I could easily change isObject to accept objects with null prototypes, but it might be trickier to return an object that also has a null prototype. Would it be okay to create a vanilla object when it clones?

@ngbrown
Copy link
Author

ngbrown commented Nov 1, 2018

Yes, returning a vanilla (frozen) object is fine. Right now to work around this, I'm rebuild that object before merging. {...query}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants