Skip to content

Commit 6ca1909

Browse files
Added toggle step, pending delete step (logic to delete from the db?)
1 parent bbbcc85 commit 6ca1909

File tree

5 files changed

+40
-7
lines changed

5 files changed

+40
-7
lines changed

resources/benchmark-runner.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ class Page {
123123
addEventListener(name, listener) {
124124
this._frame.contentWindow.addEventListener(name, listener);
125125
}
126+
127+
setGlobalVariable(name, value) {
128+
this._frame.contentWindow[name] = value;
129+
}
126130
}
127131

128132
const NATIVE_OPTIONS = {

resources/tests.mjs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,33 @@ Suites.push({
267267
}
268268
await indexedDBAddPromise;
269269
}),
270-
// new BenchmarkTestStep("CompletingAllItems", (page) => {
271-
// const items = page.querySelectorAll("todo-item", ["todo-app", "todo-list"]);
272-
// for (let i = 0; i < numberOfItemsToAdd; i++) {
273-
// const item = items[i].querySelectorInShadowRoot(".toggle-todo-input");
274-
// item.click();
275-
// }
276-
// }),
270+
new BenchmarkTestStep("CompletingAllItems", async (page) => {
271+
const numberOfItemsPerIteration = 10;
272+
const numberOfIterations = 10;
273+
page.setGlobalVariable("numberOfItemsToAdd", numberOfItemsToAdd);
274+
const indexedDBCompletedPromise = new Promise((resolve) => {
275+
page.addEventListener("indexeddb-toggle-completed", () => {
276+
resolve();
277+
});
278+
});
279+
for (let j=0; j < numberOfIterations; j++) {
280+
const items = page.querySelectorAll("todo-item", ["todo-app", "todo-list"]);
281+
for (let i = 0; i < numberOfItemsPerIteration; i++) {
282+
const item = items[i].querySelectorInShadowRoot(".toggle-todo-input");
283+
item.click();
284+
}
285+
// Let the layout update???
286+
// Give a change to the pending indexedDB operations to complete in main thread.
287+
await new Promise((resolve) => {
288+
setTimeout(() => {resolve();}, 0);
289+
});
290+
if (j<9) {
291+
const nextPageButton = page.querySelector(".next-page-button", ["todo-app", "todo-bottombar"]);
292+
nextPageButton.click();
293+
}
294+
}
295+
await indexedDBCompletedPromise;
296+
}),
277297
// new BenchmarkTestStep("DeletingAllItems", (page) => {
278298
// const items = page.querySelectorAll("todo-item", ["todo-app", "todo-list"]);
279299
// for (let i = numberOfItemsToAdd - 1; i >= 0; i--) {

resources/todomvc/vanilla-examples/javascript-wc-indexeddb/dist/components/todo-list/todo-list.component.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class IndexedDBManager {
1111
this.storeName = 'todos';
1212
this.db = null;
1313
this.pendingAdditions = 0;
14+
this.totalItemsToggled = 0;
1415
this.initDB().then(() => {
1516
const newDiv = document.createElement("div");
1617
newDiv.classList.add("indexeddb-ready");
@@ -190,6 +191,9 @@ class IndexedDBManager {
190191

191192
updateRequest.onsuccess = () => {
192193
console.log(`Todo item with itemNumber '${itemNumber}' completed status updated to: ${completed}`);
194+
if (window.numberOfItemsToAdd && ++this.totalItemsToggled === window.numberOfItemsToAdd) {
195+
window.dispatchEvent(new CustomEvent("indexeddb-toggle-completed", {}));
196+
}
193197
resolve(todoItem);
194198
};
195199

resources/todomvc/vanilla-examples/javascript-wc-indexeddb/src/components/todo-bottombar/todo-bottombar.component.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class TodoBottombar extends HTMLElement {
115115

116116
reenablePreviousPageButton() {
117117
this.element.querySelector(".previous-page-button").disabled = false;
118+
window.dispatchEvent(new CustomEvent("previous-page-button-enabled", {}));
118119
}
119120

120121
connectedCallback() {

resources/todomvc/vanilla-examples/javascript-wc-indexeddb/src/components/todo-list/todo-list.component.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class IndexedDBManager {
1111
this.storeName = 'todos';
1212
this.db = null;
1313
this.pendingAdditions = 0;
14+
this.totalItemsToggled = 0;
1415
this.initDB().then(() => {
1516
const newDiv = document.createElement("div");
1617
newDiv.classList.add("indexeddb-ready");
@@ -190,6 +191,9 @@ class IndexedDBManager {
190191

191192
updateRequest.onsuccess = () => {
192193
console.log(`Todo item with itemNumber '${itemNumber}' completed status updated to: ${completed}`);
194+
if (window.numberOfItemsToAdd && ++this.totalItemsToggled === window.numberOfItemsToAdd) {
195+
window.dispatchEvent(new CustomEvent("indexeddb-toggle-completed", {}));
196+
}
193197
resolve(todoItem);
194198
};
195199

0 commit comments

Comments
 (0)