Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions docs-app/app/templates/6-utils/incremental-each.gjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ export default class IncrementalEachDemo extends Component {
stopTicker = () => clearInterval(this.tickId);

sample = () => {
if (this.done) return;
this.elapsedMs = Math.round(performance.now() - this.startedAt);
const rendered = document.querySelectorAll('.incremental-demo li').length;
this.batches = Math.ceil(rendered / BATCH_SIZE);
};

startTicker = () => {
this.stopTicker();
this.tickId = setInterval(this.sample, 50);
this.tickId = setInterval(this.sample, 100);
};

handleDone = () => {
Expand All @@ -70,26 +71,41 @@ export default class IncrementalEachDemo extends Component {
this.stopTicker();
};

toggleMode = () => {
toggleMode = async () => {
this.handleDone();
this.stop();
this.mode = this.mode === 'lazy' ? 'sync' : 'lazy';
this.startTicker();
// we have to give enough time for ember to delete all the nodes from
// the stop() call above
requestAnimationFrame(() => {
this.start();
});
};

start = () => {
this.startedAt = performance.now();
this.done = false;
this.elapsedMs = 0;
this.batches = 0;
this.visible = true;
this.startTicker();
}

stop = () => {
this.visible = false;
this.done = false;
this.elapsedMs = 0;
this.batches = 0;
this.stopTicker();
}

toggle = () => {
if (this.visible) {
this.visible = false;
this.done = false;
this.elapsedMs = 0;
this.batches = 0;
this.stopTicker();
} else {
this.startedAt = performance.now();
this.done = false;
this.elapsedMs = 0;
this.batches = 0;
this.visible = true;
this.startTicker();
this.stop();
return;
}

this.start();
};

<template>
Expand Down
Loading