vscroll
Version:
Virtual scroll engine
63 lines • 1.85 kB
JavaScript
import { Reactive } from './reactive';
import { WorkflowCycleModel } from './state/cycle';
import { FetchModel } from './state/fetch';
import { ClipModel } from './state/clip';
import { RenderModel } from './state/render';
import { ScrollModel } from './state/scroll';
export class State {
get time() {
return Number(new Date()) - this.initTime;
}
constructor(packageInfo, settings, state) {
this.packageInfo = packageInfo;
this.settings = settings;
this.initTime = Number(new Date());
this.paused = new Reactive(false);
this.cycle = new WorkflowCycleModel(this.settings.instanceIndex, state ? state.cycle : void 0);
this.fetch = new FetchModel(settings.directionPriority);
this.clip = new ClipModel();
this.render = new RenderModel();
this.scroll = new ScrollModel();
}
startWorkflowCycle(isInitial, initiator) {
this.cycle.start(isInitial, initiator);
}
endWorkflowCycle(count) {
this.cycle.end(count);
}
startInnerLoop() {
const { cycle, scroll: scroll, fetch, render, clip } = this;
cycle.innerLoop.start();
scroll.positionBeforeAsync = null;
if (!fetch.simulate) {
fetch.reset();
}
clip.reset(clip.force);
render.reset();
return Object.assign({}, (cycle.innerLoop.first ? {
process: cycle.initiator,
doRender: fetch.simulate && fetch.items.length > 0
} : {}));
}
endInnerLoop() {
const { fetch, clip, render, cycle } = this;
fetch.stopSimulate();
clip.reset(true);
if (fetch.cancel) {
fetch.cancel();
fetch.cancel = null;
}
if (render.cancel) {
render.cancel();
render.cancel = null;
}
cycle.innerLoop.done();
}
dispose() {
this.scroll.stop();
this.cycle.dispose();
this.paused.dispose();
this.endInnerLoop();
}
}
//# sourceMappingURL=state.js.map