Skip to content

splicein DefineListt removing undefined values in source array #471

@mitch-mitchel

Description

@mitch-mitchel

How often can you reproduce it?

  • Always
  • Sometimes
  • Rarely
  • Unable
  • I didn’t try

Description:
If the source array for a new DefineList contains only values of undefined at each index, it passes the allSame test here when calling splice:

can-define/list/list.js

Lines 294 to 297 in ea827f8

// Now lets check if anything will change
if (this[i + index] !== args[listIndex]) {
allSame = false;
}

as it thinks nothing will change, and ends up returning a DefineList of length 0. As long as at least one element in the source array is not undefined it works as expected.

var undefinedList = new DefineList([undefined, undefined])
console.log('so much empty', undefinedList.length) //=> 0

See this codepen example:
https://codepen.io/mikemitchel/pen/eYOMwmE

Expected results:
I expected in the first example of the codepen to have a DefineList of length 2, with the value at each index being undefined.

Environment:

Software Version
can-define version "^2.7.10"
Browser Chrome Version 76.0.3809.132 (Official Build) (64-bit)
Operating system MacOS 10.14.6 (18G95)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions