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

The example in the Readme is flawed #1

Open
pepkin88 opened this issue Jul 5, 2021 · 0 comments
Open

The example in the Readme is flawed #1

pepkin88 opened this issue Jul 5, 2021 · 0 comments

Comments

@pepkin88
Copy link

pepkin88 commented Jul 5, 2021

I stumbled upon this library by accident, wasn't searching for it, but couldn't help but noticed, that the code in the example is flawed.

This is the example code in the README.md:

const pickOriginal = require('@ladjs/pick-original');

function createObj(doc) {
  doc.id = Date.now().toString();
  return doc;
}

const original = { foo: 'bar' };

const transformed = pickOriginal(createObj(original), original);

console.log(transformed);

// { foo: 'bar' }

The last comment suggest, that { foo: 'bar' } is printed in the console. But it isn't, because createObj(original) mutates original, so both arguments of pickOriginal are the same mutated object.

I've run this on RunKit and, as expected, it returned {foo: "bar", id: "1625507940804"}.

But I don't think that is the biggest issue. The example doesn't actually shows, what this library does. Upon inspecting the code, I learned, that pickOriginal takes out fields existing on the object in the second argument from the object in the first argument, and returns the newly created object. The example in the readme doesn't show anything like that.

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

1 participant