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

Return object from the .set() method #42

Merged
merged 4 commits into from Jul 24, 2017

Conversation

kjellmorten
Copy link
Contributor

@kjellmorten kjellmorten commented Jul 13, 2017

Just a small change to return the object from the set method. I find it convenient in some cases, and it does not add any significant overhead.

Feel free to merge if this makes sense to you. Tests and readme are updated accordingly.

@sindresorhus
Copy link
Owner

@sindresorhus sindresorhus commented Jul 22, 2017

I find it convenient in some cases

Do you have an example of that? I'm trying to think of when it would be useful.

readme.md Outdated
@@ -59,7 +63,7 @@ console.log(obj);

### get(obj, path, [defaultValue])

### set(obj, path, value)
### obj = set(obj, path, value)
Copy link
Owner

@sindresorhus sindresorhus Jul 23, 2017

Choose a reason for hiding this comment

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

Better to write it in text. Something like:

Returns the object.

Copy link
Contributor Author

@kjellmorten kjellmorten Jul 24, 2017

Choose a reason for hiding this comment

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

Thanks! See new commit.

@kjellmorten
Copy link
Contributor Author

@kjellmorten kjellmorten commented Jul 24, 2017

@sindresorhus As an example, I have a function that takes a value, does something to it, and returns it at a path in a new object. (The path is provided at run-time, so regular JS object notation is not an option.)

When set does not return the object, I have to write:

const object = {}
set(object, path, value)
return object

With this PR I could simply write:

return set({}, path, value)

It's not a big issue – just for convenience. :)

@sindresorhus
Copy link
Owner

@sindresorhus sindresorhus commented Jul 24, 2017

Makes sense. Can you use something like that in the readme example too? const foo = obj => dotProp.set(obj, 'unicorn', '🦄'); Makes it easier to understand the use-case of it.

@kjellmorten
Copy link
Contributor Author

@kjellmorten kjellmorten commented Jul 24, 2017

Sure. I had an example of the return value, but it wasn't clear enough. Changed the input to an empty object, so it is clearer what the point of it is.

Sorry I didn't return a unicorn.

@sindresorhus sindresorhus changed the title Return object from set method Return object from the .set() method Jul 24, 2017
@sindresorhus sindresorhus merged commit df49d33 into sindresorhus:master Jul 24, 2017
1 check was pending
@kjellmorten kjellmorten deleted the return-from-set branch Jul 24, 2017
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.

None yet

2 participants