-
Notifications
You must be signed in to change notification settings - Fork 7
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
State.slice()
produces slices with undefined values if indices are out of bounds.
#48
Comments
Thanks @cowboyd! Sounds like a candidate to fix before a 1.0 release. I'll open a PR with a failing test and tackle this in the first half of this week. |
@cowboyd I was not able to reproduce the issue you're describing. Could you provide more detail? I've got a branch up with the tests for Since an instance of |
Weird! We had to put in a workaround in to get what we thought was the proper slice behavior https://github.com/folio-org/ui-eholdings/blob/master/src/components/impagination.js#L20-L35 But maybe we were using it wrong 🤔 |
Yea from the looks of it, does not seem different than what standard JS slice would be returning. Using your extended ‘slice’ method as a wrapper to datasetState.slice, i’m curious what the values of ‘start’, ‘end’, ‘datasetState.length’ and ‘result.length’ would be. |
Maybe @wwilsman could shed some light here since he did the bulk of the implementation. |
Hey @flexyford! Sorry it took me so long to get around to looking at this! So the problem is actually not that the array is the wrong length, but that the values are undefined. state.slice(0, 2) //=> [undefined, undefined] So this is the problem we were facing:
Because we are waiting to call state = new State({ pageSize: 10, readOffset: 20 });
state.slice(9, 11); //=> [undefined, { page, content, ... }] After some digging, this looks like it might be intended? After calling The confusion comes from when we use the let state = new State({ pageSize: 25, stats: { totalPages: 400 } });
expect(state).to.have.lengthOf(10000);
//=> true
expect(state.slice(5000, 5026)).to.have.lengthOf(25);
//=> true
// this is the desired behavior
expect(state.slice(5000, 5026)[0]).to.deep.equal(state.getRecord(5000));
//=> false
// after we set the read offset, this is true
state = state.setReadOffset(5000);
expect(state.slice(5000, 5026)[0]).to.deep.equal(state.getRecord(5000));
//=> true Since we are debouncing |
The standard behavior for slice is to truncate the slice for any values of
start
andend
that are out of bounds, so for example, no matter how you slice an empty array, you still get the empty array:for the dataset state however, slicing with indices that fall outside the length of the state produces array slots that are all inhabited by
undefined
The text was updated successfully, but these errors were encountered: