Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed immutable array reducer bug (#1591)
* Fixed immutable array reducer bug * linting
- Loading branch information
Showing
12 changed files
with
640 additions
and
104 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { some } from 'lodash' | |
|
||
const structure = { | ||
empty: {}, | ||
emptyList: [], | ||
getIn, | ||
setIn, | ||
deepEqual, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
const splice = (array = [], index, removeNum, value) => { | ||
if (index < array.length) { | ||
if (value != null) { | ||
if (value === undefined && !removeNum) { // inserting undefined | ||
const copy = [ ...array ] | ||
copy.splice(index, removeNum, value) // removing and adding | ||
copy.splice(index, 0, null) | ||
copy[ index ] = undefined | ||
return copy | ||
} else { | ||
} | ||
if (value != null) { | ||
const copy = [ ...array ] | ||
copy.splice(index, removeNum) // removing | ||
copy.splice(index, removeNum, value) // removing and adding | ||
return copy | ||
} | ||
} | ||
if (value != null) { | ||
const copy = [ ...array ] | ||
copy[index] = value | ||
copy.splice(index, removeNum) // removing | ||
return copy | ||
} | ||
return array | ||
if (removeNum) { // trying to remove non-existant item: return original array | ||
return array | ||
} | ||
// trying to add outside of range: just set value | ||
const copy = [ ...array ] | ||
copy[ index ] = value | ||
return copy | ||
} | ||
|
||
export default splice |