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

fix: removing element from an array doesn't insert null anymore #16 #17

Merged
merged 2 commits into from
Dec 30, 2019

Conversation

gbersac
Copy link
Contributor

@gbersac gbersac commented Nov 12, 2019

#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).

@@ -655,6 +655,26 @@ describe('immupdate', () => {
expect(updated4).toNotBe(obj2)
})

it('can delete an element of an array', () => {
Copy link
Contributor Author

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
Copy link
Contributor Author

@gbersac gbersac Nov 12, 2019

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
Copy link
Contributor Author

@gbersac gbersac Nov 12, 2019

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).

@gbersac gbersac marked this pull request as ready for review November 12, 2019 16:33
@AlexGalays AlexGalays merged commit 2a67518 into AlexGalays:master Dec 30, 2019
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