Clear Arrays when pushing an Array #158
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
if
-statement in thecustomizer
-function to check ifsrcValue
is atypeof
Array
.Array.map
to convert all values that areundefined
ornull
tonull
.undefined
ornull
values usingArray.filter
as the end result is the same but I decided onArray.map
in order to mimic the behavior of the existingif
-statement above the new code.Array
.With these changes, pushing an
Array
to an existingArray
-property will completely override the existingArray
instead of merging the two together. Pushing an emptyArray
will clear the existingArray
.Current Behavior
New Behavior
Related Issue
Motivation and Context
The documentation under Pushing an Object to Update an Existing Array states:
This statement is contradictory to the current behavior.
It is unexpected behavior that assigning a new
Array
to an existingArray
-property merges the new and existingArray
's together.Mitigates the need to explicitly assign a
null
value to an existingArray
-property before pushing a newArray
.Allows for clearing
Array
's by pushing an emptyArray
.How Has This Been Tested?
npm run test
in forked repository workspace.npm run dev
in forked repository and testing using the browser console on the providedlocalhost
test page.Array
-property to existingArray
-property.Array
-property to existingArray
-property nested in anotherObject
.Screenshots
npm run test
Types of Changes
Checklist: