can-define icon indicating copy to clipboard operation
can-define copied to clipboard

`splice`in DefineListt removing `undefined` values in source array

Open mitch-mitchel opened this issue 6 years ago • 0 comments

How often can you reproduce it?

  • [x] 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: https://github.com/canjs/can-define/blob/ea827f80dbac95dceb55384cc9730566d4b488f7/list/list.js#L294-L297

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)

mitch-mitchel avatar Sep 11 '19 20:09 mitch-mitchel