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

setWith extraArgs #37

Closed
alexesDev opened this issue Oct 26, 2019 · 3 comments · Fixed by #38
Closed

setWith extraArgs #37

alexesDev opened this issue Oct 26, 2019 · 3 comments · Fixed by #38

Comments

@alexesDev
Copy link

Hi. Why setWith not working?

setWith((_, x) => x, 'test', { test: 1 }, 2);
{ test: [Function: bound slice] }

Also

const fn: unchanged.withHandler = (value: any, preventUpdate: boolean): any =>
  preventUpdate ? currentValue : "quz";

console.log(setWith(fn, "foo[0].bar", object)); // {foo: [{bar: 'quz'}]}

Print

{ foo: [ { bar: 'baz' } ] }
@alexesDev alexesDev changed the title setWith setWith extraArgs Oct 26, 2019
@alexesDev
Copy link
Author

This is a very strange code 😮

const slice = Function.prototype.bind.call(Function.prototype.bind, Array.prototype.slice);

Why not just Array.prototype.slice.call?

@planttheidea
Copy link
Owner

planttheidea commented Oct 26, 2019

Ha okay so this is a stupid mistake on my part ... the first param of that setup should be Function.prototype.call, not Function.prototype.bind. Not sure why my testing didn't catch this, but I'll update.

To answer your question, it avoids property access. It's a micro-optimization that had a slight perf win in specific legacy environments.

@planttheidea
Copy link
Owner

planttheidea commented Oct 26, 2019

This should be fixed in 2.2.1. Thanks for calling this out!

Also, I realized my ambiguous wording in my previous response could be misinterpreted (what I get for replying at 4:30AM). This was a totally valid issue, the stupid thing was my mistake, so apologies for the miscommunication.

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 a pull request may close this issue.

2 participants