Skip to content
This repository was archived by the owner on Jul 24, 2023. It is now read-only.

Commit 7ab385c

Browse files
committed
refactor: drop postrender events in favor of resizeObserver
1 parent 631d81f commit 7ab385c

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

app/views/common/translation-key.js

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,5 @@ customElements.define('translation-key', class TranslationKey extends HTMLElemen
1818
} else {
1919
this.textContent = await app?.translate(this.#key);
2020
}
21-
22-
dispatch(this, 'postrender');
2321
}
2422
});

app/views/preferences/preferences.html

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html class="is-native -transparent">
2+
<html @keydown.window="onKeyDown" class="is-native -transparent">
33
<head>
44
<meta charset="utf-8">
55
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'sha256-rsIvmmZP7gi++DMJu/EmEuqN8OZoShxV4vpYFEUSSEI='">
@@ -46,13 +46,7 @@ <h1 class="name" :text="productName"></h1>
4646
</div>
4747
</section>
4848

49-
<form
50-
#$form
51-
@input="onInput"
52-
@postrender="onPostRender"
53-
@keydown.window="onKeyDown"
54-
class="contents preferences-contents"
55-
>
49+
<form #$form @input="onInput" class="contents preferences-contents">
5650
<section class="content" #$content>
5751
<label class="form-group">
5852
<input type="checkbox" name="openAtLogin" class="action -toggle">

app/views/preferences/renderer.js

+22-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { bindAttributes, bindEventListeners, findReferences } from '@browserkids
33
window.renderer = new class Renderer {
44
#isPackaged = null;
55

6+
#resize = null;
7+
68
constructor({ app, preferences }) {
79
this.$root = document.documentElement;
810
this.$refs = findReferences(this.$root);
@@ -17,7 +19,21 @@ window.renderer = new class Renderer {
1719
});
1820

1921
this.app.on('update-downloaded', this.onUpdateDownloaded.bind(this));
20-
this.render();
22+
23+
this
24+
.createObserver({ resize: true })
25+
.render();
26+
}
27+
28+
createObserver(settings = {}) {
29+
const { resize = false } = settings;
30+
31+
if (resize) {
32+
this.#resize = new ResizeObserver(this.onResize.bind(this));
33+
this.#resize.observe(this.$root);
34+
}
35+
36+
return this;
2137
}
2238

2339
onCategoryClicked({ currentTarget }) {
@@ -54,17 +70,17 @@ window.renderer = new class Renderer {
5470
}
5571
}
5672

57-
onPostRender() {
73+
onQuitClicked() {
74+
this.app.quit();
75+
}
76+
77+
onResize() {
5878
this.app.resizeWindow({
5979
height: this.$root.offsetHeight,
6080
width: this.$root.offsetWidth,
6181
});
6282
}
6383

64-
onQuitClicked() {
65-
this.app.quit();
66-
}
67-
6884
onRestartClicked() {
6985
this.app.restart();
7086
}

0 commit comments

Comments
 (0)