Skip to content

Commit c98376a

Browse files
committed
simplify and improve row selection logic
1 parent 6812937 commit c98376a

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ After that you can check all results in [http://localhost:8080/webdriver-ts/tabl
309309
3. Visit your page in the browser (URL follows the folder structure): `http://localhost:8080/frameworks/keyed/fast/index.html`
310310
4. Note: Its important to always start the server from the root, because that way you'll get access to global CSS that all apps must share
311311
5. Add the "action triggers" - buttons that all apps must have (see `frameworks/keyed/vanillajs/index.html`)
312-
1. Note: Action triggers are simply buttons that are used to run the benchmarks (adding rows, deleting rows, swapping them, etc). Those buttons can be static HTML, or you can render them with your framework of choice
312+
1. Note: Action triggers are simply buttons that are used to run the benchmarks (adding rows, deleting rows, swapping them, etc). Those buttons can be static HTML, or you can render them dynamically (with JS) with your framework of choice
313313
2. Make sure your HTML elements have the same classes and structure as VanillaJS, otherwise benchmarks won't be able to find your elements on the page, and you will not get the global CSS (Bootstrap)
314314
3. Add the html example below and open the page. You should see nicely formatted elements on the page, like in the GIF image below.
315315
4. Example for action triggers
@@ -392,7 +392,7 @@ After that you can check all results in [http://localhost:8080/webdriver-ts/tabl
392392
6. Generate dummy data for rendering
393393
1. See `frameworks/keyed/fast/src/utils/build-dummy-data.ts` as an example
394394
2. Note: `id` is an important attribute and it must be initialized as `1`, and continuously incremented. The only time `id` resets back to `1` is when the page reloads - otherwise it should just keep incrementing each time a new row is created. Doing anything else will cause errors when benchmarks try to find elements with specific IDs. Trust me, I learned the hard way.
395-
7. . Your app needs to support several actions that correspond to "Action triggers" listed above. Here's an example from Fast framework:
395+
7. . Your app needs to support several actions that correspond to "Action triggers" listed above. Here's an example from Fast framework `frameworks\keyed\fast\src\App.ts` and `frameworks\keyed\fast\src\components\Table.ts`:
396396
1. Code example:
397397
```typescript
398398
export class BenchmarkApp extends FASTElement {
@@ -404,25 +404,29 @@ After that you can check all results in [http://localhost:8080/webdriver-ts/tabl
404404
swapTwoRows() {}
405405
deleteSingleRow(rowId: number) {}
406406
}
407+
408+
export class Table extends FASTElement {
409+
selectRow(rowId: number) {}
410+
}
407411
```
408-
2. Note: your app doesn't need methods with the same name - you should write idiomatic code and follow the best practices of your framework of choice. The example above is just to give you an idea of which operations must be supported, but how you choose to implement those methods can be very different from one framework to the next.
409-
8. Manually testing your app - do this before you run the benchmarks
412+
1. Note: your app doesn't need methods with the same name - you should write idiomatic code and follow the best practices of your framework of choice. The example above is just to give you an idea of which operations must be supported, but how you choose to implement those methods can be very different from one framework to the next.
413+
1. Manually testing your app - do this before you run the benchmarks
410414
1. Open your page and click on the buttons, make sure your app adds 1000 rows, then removes them, or swaps them, or adds/removes 10,000 rows.
411415
2. To do this, you'll probably need to watch your local files and compile them into some sort of a bundle, like `frameworks\keyed\fast\dist\bundle.js` which will be loaded through a script tag in your HTML file
412416
3. For example, in Fast folder we have webpack watching our files: ` "build-dev": "rimraf dist && webpack --config webpack.config.js --watch --mode=development",`
413417
4. That means we have two terminal tabs running
414418
1. One for the server from the root folder `npm start`
415419
2. And another in our local folder where webpack is watching the files
416-
9. Run the single benchmark for your framework
420+
2. Run the single benchmark for your framework
417421
1. Once you manually verified that everything works as expected, run a single benchmark and make sure all of the tests are running
418422
2. If you forgot something, one of the benchmarks will probably fail - for example it won't be able to find an element on the page or similar
419423
3. Keep the server in the root folder running `npm start`, and in another terminal tab, also from the root folder run `npm run bench -- --framework keyed/fast` (or whatever is your framework `keyed/react`, `keyed/angular`, etc.).
420424
4. The benchmark runner will open and close Chrome multiple times. The whole thing will take a couple of minutes.
421-
10. Optional: run the benchmark for VanillaJS as comparison
425+
3. Optional: run the benchmark for VanillaJS as comparison
422426
1. ` npm run bench -- --framework keyed/vanillajs`
423-
11. Build the report
427+
4. Build the report
424428
1. `npm run results`
425-
12. Open the report in your browser (NOTE: the server must still be running if you want to see this page)
429+
5. Open the report in your browser (NOTE: the server must still be running if you want to see this page)
426430
1. `http://localhost:8080/webdriver-ts-results/table.html`
427431

428432
## 4.1 Building the app

frameworks/keyed/fast/src/components/Table.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,12 @@ export class Table extends FASTElement {
6262

6363
if (target.classList.contains('lbl')) {
6464
const rowId = target.dataset['rowId'];
65-
this.toggleSelectRow(Number(rowId));
65+
this.selectRow(Number(rowId));
6666
return;
6767
}
6868
}
6969

70-
toggleSelectRow(rowId: number) {
71-
const rowIndex = this.rows.findIndex(row => row.id === rowId);
72-
if (rowIndex > -1) {
73-
this.selectedRowId = rowIndex + 1;
74-
}
70+
private selectRow(rowId: number) {
71+
this.selectedRowId = rowId;
7572
}
7673
}

0 commit comments

Comments
 (0)