-
Notifications
You must be signed in to change notification settings - Fork 8
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
fix: removing element from an array doesn't insert null anymore #16 #17
Conversation
@@ -655,6 +655,26 @@ describe('immupdate', () => { | |||
expect(updated4).toNotBe(obj2) | |||
}) | |||
|
|||
it('can delete an element of an array', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check if there is enough test.
@@ -253,7 +258,7 @@ class _Updater { | |||
const nextValue = clone(value) | |||
const newHost = isLast ? host : nextValue | |||
|
|||
host[this.data.field] = nextValue | |||
if (nextValue !== undefined) host[this.data.field] = nextValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line has been modified to pass this test :
// test if nothing happen when the element to delete is widely out of array's bound
const updated3 = deepUpdate(data).at('a').at(5).set(DELETE)
expect(updated3).toEqual(data)
Previous behaviour was to create the following object {a: [1, 2, 3, null, null]}
All unit tests pass, but I wonder, if it could introduced non tested regression.
if (leafHostIsOption) { | ||
|
||
if (Array.isArray(leafHost) && typeof field === 'number') { | ||
if (field >= leafHost.length) return target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modifying this line to if (field >= leafHost.length || (field == leafHost.length && value !== DELETE)) return target
should give the user the ability to append an element to the array (if this feature is valuable).
3bf90d8
to
2a67518
Compare
#16
With this PR, trying to update an element which is out of bound of an array will do nothing (remove the ability to append an element at the end of an array).