Skip to content

Commit

Permalink
Merge pull request #217 from dhilt/issue-213-duble-clip-fix
Browse files Browse the repository at this point in the history
Double clip case
  • Loading branch information
dhilt authored Oct 5, 2020
2 parents 5e62317 + fa7b82d commit 22ec2a0
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package-dist.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-ui-scroll",
"version": "1.8.4",
"version": "1.8.5",
"description": "Infinite/virtual scroll for Angular",
"main": "./bundles/ngx-ui-scroll.umd.js",
"module": "./fesm5/ngx-ui-scroll.js",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"deploy-app": "npm run build-app && firebase deploy",
"preinstall": "cd server && npm install",
"postinstall": "npm run build-app",
"pack:install": "npm run build && npm pack ./dist && npm install ngx-ui-scroll-1.8.4.tgz --no-save",
"pack:install": "npm run build && npm pack ./dist && npm install ngx-ui-scroll-1.8.5.tgz --no-save",
"pack:start": "npm run pack:install && npm start",
"build": "node build.js",
"publish:lib": "npm run build && npm publish ./dist",
Expand Down
8 changes: 6 additions & 2 deletions src/component/classes/state/clip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ export class ClipModel {
this.reset();
}

reset() {
reset(isForce?: boolean) {
this.doClip = false;
this.forceReset();
if (!isForce) {
this.forceReset();
} else {
this.simulate = false;
}
}

forceReset() {
Expand Down
14 changes: 8 additions & 6 deletions src/component/processes/clip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ export default class Clip {
buffer.items = buffer.items.filter(({ toRemove }) => !toRemove);
}

logger.log(() => [
`clipped ${itemsToRemove.length} items` +
(size.backward ? `, +${size.backward} fwd px` : '') +
(size.forward ? `, +${size.forward} bwd px` : '') +
`, range: [${itemsToRemove[0].$index}..${itemsToRemove[itemsToRemove.length - 1].$index}]`
]);
logger.log(() => itemsToRemove.length
? [
`clipped ${itemsToRemove.length} items` +
(size.backward ? `, +${size.backward} fwd px` : '') +
(size.forward ? `, +${size.forward} bwd px` : '') +
`, range: [${itemsToRemove[0].$index}..${itemsToRemove[itemsToRemove.length - 1].$index}]`
]
: 'clipped 0 items');

viewport.scrollPosition = position;

Expand Down
4 changes: 2 additions & 2 deletions src/component/processes/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default class Start {
if (!fetch.simulate) {
fetch.reset();
}
if (!clip.simulate && !clip.force) {
clip.reset();
if (!clip.simulate) {
clip.reset(clip.force);
}
render.reset();

Expand Down
2 changes: 1 addition & 1 deletion src/ui-scroll.version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default '1.8.4';
export default '1.8.5';
20 changes: 20 additions & 0 deletions tests/bug.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,24 @@ describe('Bug Spec', () => {
});
});

describe('double clip', () =>
makeTest({
title: 'should clip once',
config: {
datasourceName: 'default',
datasourceSettings: { adapter: true, bufferSize: 50 }
},
it: (misc: Misc) => async (done: Function) => {
const { clip } = misc.scroller.state;
await misc.relaxNext();
expect(clip.callCount).toEqual(0);
await misc.adapter.clip();
expect(clip.callCount).toEqual(1);
await misc.adapter.clip();
expect(clip.callCount).toEqual(1);
done();
}
})
);

});

0 comments on commit 22ec2a0

Please sign in to comment.