Skip to content

Commit

Permalink
Merge pull request #166 from dhilt/issue-165-inertia-scroll-processing
Browse files Browse the repository at this point in the history
Inertia scroll
  • Loading branch information
dhilt authored Apr 6, 2020
2 parents ee24e99 + 1974158 commit 6f58be8
Show file tree
Hide file tree
Showing 29 changed files with 292 additions and 659 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ testem.log
.DS_Store
Thumbs.db

# firebase
.firebase
.firebaserc
firebase.json

temp
3 changes: 0 additions & 3 deletions demo/app/samples/test.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ export class TestComponent {
logTime: false,
logProcessRun: true,
throttle: 40,
inertia: true,
inertiaScrollDelay: 55,
inertiaScrollDelta: 135,
changeOverflow: false
}
});
Expand Down
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.5.3",
"version": "1.6.0",
"description": "Infinite/virtual scroll for Angular",
"main": "./bundles/ngx-ui-scroll.umd.js",
"module": "./fesm5/ngx-ui-scroll.js",
Expand Down
33 changes: 12 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
"lint": "tslint -c tslint.json --project . ",
"test": "npm run lint && karma start",
"build-app": "ng build --prod --aot --source-map",
"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.5.3.tgz --no-save",
"pack:install": "npm run build && npm pack ./dist && npm install ngx-ui-scroll-1.6.0.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 Expand Up @@ -70,7 +71,7 @@
"raw-loader": "0.5.1",
"reflect-metadata": "0.1.12",
"rollup": "0.66.6",
"rollup-plugin-license": "^0.13.0",
"rollup-plugin-license": "^2.0.0",
"rollup-plugin-node-resolve": "3.4.0",
"rollup-plugin-sourcemaps": "0.4.2",
"sass-loader": "7.1.0",
Expand Down
39 changes: 13 additions & 26 deletions src/component/classes/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export class Logger {
readonly getWorkflowCycleData: Function;
readonly getLoop: Function;
readonly getLoopNext: Function;
readonly getWorkflowOptions: Function;
readonly getSynthScrollState: Function;
readonly getScrollPosition: Function;
private logs: any[] = [];

Expand Down Expand Up @@ -47,8 +45,6 @@ export class Logger {
this.getLoopNext = (): string => scroller.state.loopNext;
this.getWorkflowCycleData = (): string =>
`${settings.instanceIndex}-${scroller.state.workflowCycleCount}`;
this.getWorkflowOptions = () => scroller.state.workflowOptions;
this.getSynthScrollState = () => scroller.state.syntheticScroll;
this.getScrollPosition = (element: HTMLElement) => scroller.routines.getScrollPosition(element);
this.log(() => `uiScroll Workflow has been started (v${version}, instance ${settings.instanceIndex})`);
}
Expand Down Expand Up @@ -80,17 +76,6 @@ export class Logger {
}
}

synth(token?: string) {
this.log(() => {
const synth = this.getSynthScrollState();
return [
...(token ? [token + ';'] : []),
'registered', synth.registeredPosition,
'/ queued', synth.list.map((i: any) => i.position)
];
});
}

prepareForLog(data: any) {
return data instanceof Event
? this.getScrollPosition(data.target)
Expand All @@ -102,26 +87,18 @@ export class Logger {
return;
}
const { process, status } = data;
const options = this.getWorkflowOptions();

// standard process log
// const processLog = `process ${process}, %c${status}%c` + (!options.empty ? ',' : '');
// const styles = [status === Status.error ? 'color: #cc0000;' : '', 'color: #000000;'];
// this.log(() => [processLog, ...styles, data.payload, ...(!options.empty ? [options] : [])]);

// inner loop start-end log
const loopLog: string[] = [];
if (
process === Process.init && status === Status.next ||
process === Process.scroll && status === Status.next && options.keepScroll ||
process === Process.end && status === Status.next && options.byTimer
process === Process.init && status === Status.next
) {
loopLog.push(`%c---=== loop ${this.getLoopNext()} start`);
} else if (
process === Process.end && !options.byTimer
process === Process.end
) {
loopLog.push(`%c---=== loop ${this.getLoop()} done`);
if (status === Status.next && !(options.keepScroll)) {
if (status === Status.next) {
loopLog[0] += `, loop ${this.getLoopNext()} start`;
}
}
Expand Down Expand Up @@ -189,6 +166,16 @@ export class Logger {
}
}

// logNow(...args: any[]) {
// const immediateLog = this.immediateLog;
// const debug = this.debug;
// (this as any).debug = true;
// (this as any).immediateLog = true;
// this.log.apply(this, args);
// (this as any).debug = debug;
// (this as any).immediateLog = immediateLog;
// }

logForce(...args: any[]) {
if (this.debug) {
if (!this.immediateLog && this.logs.length) {
Expand Down
13 changes: 1 addition & 12 deletions src/component/classes/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,15 @@ export const defaultDevSettings: IDevSettings = {
logTime: false, // if true, time differences will be logged
logProcessRun: false, // if true, process fire/run info will be logged
throttle: 40, // if > 0, scroll event handling is throttled (ms)
inertia: true, // if true, inertia scroll delay (ms) and delta (px) are taken into the account
inertiaScrollDelay: 125,
inertiaScrollDelta: 35,
initDelay: 1, // if set, the Workflow initialization will be postponed (ms)
initWindowDelay: 40, // if set and the entire window is scrollable, the Workflow init will be postponed (ms)
maxSynthScrollDelay: 450, // if > 0, synthetic scroll params will be reset after [value] (ms)
changeOverflow: false, // if true, scroll will be disabled per each item's average size change
};

export const minDevSettings: IDevSettings = {
throttle: 0,
inertiaScrollDelay: 0,
inertiaScrollDelta: 0,
initDelay: 0,
initWindowDelay: 0,
maxSynthScrollDelay: 0
initWindowDelay: 0
};

export class Settings implements ISettings, IDevSettings {
Expand All @@ -64,12 +57,8 @@ export class Settings implements ISettings, IDevSettings {
logTime: boolean;
logProcessRun: boolean;
throttle: number;
inertia: boolean;
inertiaScrollDelay: number;
inertiaScrollDelta: number;
initDelay: number;
initWindowDelay: number;
maxSynthScrollDelay: number;
changeOverflow: boolean;
inverse: boolean;

Expand Down
12 changes: 2 additions & 10 deletions src/component/classes/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ import { BehaviorSubject, Subject } from 'rxjs';
import {
ItemAdapter,
State as IState,
ScrollState as IScrollState,
SyntheticScroll as ISyntheticScroll,
WorkflowOptions as IWorkflowOptions
ScrollState as IScrollState
} from '../interfaces/index';

import { Settings } from './settings';
import { Logger } from './logger';
import { FetchModel } from './state/fetch';
import { ClipModel } from './state/clip';
import { RenderModel } from './state/render';
import { WorkflowOptions } from './state/workflowOptions';
import { ScrollState, SyntheticScroll } from './state/scroll';
import { ScrollState } from './state/scroll';
import { itemAdapterEmpty } from '../utils/adapter';

export class State implements IState {
Expand All @@ -29,19 +26,16 @@ export class State implements IState {
workflowCycleCount: number;
isInitialWorkflowCycle: boolean;
countDone: number;
workflowOptions: IWorkflowOptions;

fetch: FetchModel;
clip: ClipModel;
render: RenderModel;
startIndex: number;
lastPosition: number;
preFetchPosition: number;
preAdjustPosition: number;
bwdPaddingAverageSizeItemsCount: number;

scrollState: IScrollState;
syntheticScroll: ISyntheticScroll;

get time(): number {
return Number(new Date()) - this.initTime;
Expand All @@ -65,7 +59,6 @@ export class State implements IState {
this.workflowCycleCount = 1;
this.isInitialWorkflowCycle = false;
this.countDone = 0;
this.workflowOptions = new WorkflowOptions(settings);

this.setCurrentStartIndex(settings.startIndex);
this.fetch = new FetchModel();
Expand All @@ -74,7 +67,6 @@ export class State implements IState {
this.bwdPaddingAverageSizeItemsCount = 0;

this.scrollState = new ScrollState();
this.syntheticScroll = new SyntheticScroll(logger);
}

setCurrentStartIndex(newStartIndex: any) {
Expand Down
Loading

0 comments on commit 6f58be8

Please sign in to comment.