diff --git a/package-dist.json b/package-dist.json index a9a7abd6..9bb2aa68 100644 --- a/package-dist.json +++ b/package-dist.json @@ -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", diff --git a/package.json b/package.json index 1c33f777..e84dae47 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/component/classes/state/clip.ts b/src/component/classes/state/clip.ts index e22ee517..23f4d062 100644 --- a/src/component/classes/state/clip.ts +++ b/src/component/classes/state/clip.ts @@ -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() { diff --git a/src/component/processes/clip.ts b/src/component/processes/clip.ts index b695a1d9..52f9725f 100644 --- a/src/component/processes/clip.ts +++ b/src/component/processes/clip.ts @@ -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; diff --git a/src/component/processes/start.ts b/src/component/processes/start.ts index 76eade0a..43b0b31b 100644 --- a/src/component/processes/start.ts +++ b/src/component/processes/start.ts @@ -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(); diff --git a/src/ui-scroll.version.ts b/src/ui-scroll.version.ts index bb59dd51..224065d0 100644 --- a/src/ui-scroll.version.ts +++ b/src/ui-scroll.version.ts @@ -1 +1 @@ -export default '1.8.4'; +export default '1.8.5'; diff --git a/tests/bug.spec.ts b/tests/bug.spec.ts index a63774f6..e748ea86 100644 --- a/tests/bug.spec.ts +++ b/tests/bug.spec.ts @@ -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(); + } + }) + ); + });