Skip to content

Commit 75909f4

Browse files
committed
feat: add memo optimize
1 parent 3c180cf commit 75909f4

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

frameworks/keyed/vue-jsx/src/App.tsx renamed to frameworks/keyed/vue-jsx/src/App.jsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { defineComponent, ref, shallowRef } from "vue";
22
import { buildData } from "./data";
3+
import useMemo from "./useMemo";
34
export default defineComponent({
45
setup() {
6+
const memo = useMemo();
7+
const a = 1;
58
const selected = ref();
69
const rows = shallowRef([]);
710

@@ -58,6 +61,7 @@ export default defineComponent({
5861
setRows();
5962
}
6063
}
64+
6165
return () => (
6266
<div>
6367
<div class="jumbotron">
@@ -109,20 +113,22 @@ export default defineComponent({
109113

110114
<table class="table table-hover table-striped test-data">
111115
<tbody>
112-
{rows.value.map(({ id, label }) => (
113-
<tr key={id} class={{ danger: id === selected }} data-label={label}>
114-
<td class="col-md-1">{id}</td>
115-
<td class="col-md-4">
116-
<a onClick={() => select(id)}>{label}</a>
117-
</td>
118-
<td class="col-md-1">
119-
<a onClick={() => remove(id)}>
120-
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
121-
</a>
122-
</td>
123-
<td class="col-md-6"></td>
124-
</tr>
125-
))}
116+
{rows.value.map(({ id, label }) => {
117+
return memo(() => [label, id === selected])(
118+
<tr key={id} class={{ danger: id === selected }} data-label={label}>
119+
<td class="col-md-1">{id}</td>
120+
<td class="col-md-4">
121+
<a onClick={() => select(id)}>{label}</a>
122+
</td>
123+
<td class="col-md-1">
124+
<a onClick={() => remove(id)}>
125+
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
126+
</a>
127+
</td>
128+
<td class="col-md-6"></td>
129+
</tr>
130+
);
131+
})}
126132
</tbody>
127133
</table>
128134
<span class="preloadicon glyphicon glyphicon-remove" aria-hidden="true"></span>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { VNode, withMemo } from "vue";
2+
3+
export default function useMemo() {
4+
const cache = [];
5+
6+
let i = -1;
7+
8+
return (memo = () => []) => {
9+
i += 1;
10+
11+
const render = (index, toRender) => {
12+
const r = withMemo(memo(), () => toRender, cache, index);
13+
14+
if (cache.indexOf(r) !== index) {
15+
console.error("withMemo cache has been corrupted");
16+
}
17+
18+
return r;
19+
};
20+
21+
return render.bind(null, i);
22+
};
23+
}

webdriver-ts/src/puppeteerAccess.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export async function startBrowser(benchmarkOptions: BenchmarkOptions): Promise<
121121
"--disable-background-networking",
122122
"--enable-features=NetworkService,NetworkServiceInProcess",
123123
"--disable-background-timer-throttling",
124+
"--disable-extensions",
124125
// "--disable-backgrounding-occluded-windows",
125126
// "--disable-breakpad",
126127
// "--disable-client-side-phishing-detection",

0 commit comments

Comments
 (0)