jashkenas / jashkenas/underscore

Possibility to update a nested object's property in a non-mutable way

Open
#2,948 4 comments 0 reactions 0 assignees View on GitHub
enhancement starter
Dominant language
JavaScript
Stars
27.3k
Forks
5.4k
Avg merge
2d 5h
Merged PRs (30d)
1

Description

Currently I am using something like:

```typescript
const foo = bar.map((baz) => {
return {
...baz,
qux: baz.qux.map((quux) => {
return {
...quux,
aNewProperty: 'yay!'
}
}
}
});
```
To make the point clear, it would be ideal to have something similar to the [set method in lodash](https://lodash.com/docs/4.17.15#set):

```typescript
const foo = bar;
set(foo, 'bar.baz.qux.quux', { bar.baz.qux.quux, aNewPorperty: 'yay!' });
```

Note: I am not aware of how lodash and underscore are related but the current project I'm working on is using underscore. And at this time it's not possible to convert to lodash just for this single use-case.

Contributor guide

Open the contributing guide

Research direction

No source file or test is named. Start by reviewing the linked lodash set API and the existing Underscore APIs for nested updates, then define the immutable behavior and path handling for the requested example. Done means nested properties can be updated without mutating the original object, with tests covering that behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.