Skip to content

Commit dc33f09

Browse files
committed
refactor: Migrate AppShell's dynamic content generation to use computed properties for section title and HTML.
1 parent 09340a5 commit dc33f09

3 files changed

Lines changed: 13 additions & 17 deletions

File tree

app/iso.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Isomorphic modules
2-
import '../app/router.js';
32
import '../app/app.js';
43
import '../app/l10n.js';
4+
import '../app/router.js';
55
import '../components/app-shell/app-shell.js';
66
import '../components/nav-menu/nav-menu.js';
77
import '../components/i-con/i-con.js';

components/app-shell/app-shell.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,20 @@ import styles from './styles.js';
44

55
export default class AppShell extends Symbiote {
66
isoMode = true;
7-
sectionHtml = /*html*/ `<home-section></home-section>`;
8-
sectionTitle = '';
7+
init$ = {
8+
'+sectionTitle': {
9+
deps: ['router/title', 'app/currentLang'],
10+
fn: () => this.$[`l10n/${this.$['router/title']}`] || this.$['router/title'] || '',
11+
},
12+
'+sectionHtml': {
13+
deps: ['router/route'],
14+
fn: () => /*html*/ `<${this.$['router/route']}-section></${this.$['router/route']}-section>`,
15+
}
16+
}
917

1018
changeLang(e) {
1119
this.$['app/currentLang'] = e.target.value;
1220
}
13-
14-
setTitle() {
15-
this.$.sectionTitle = this.$[`l10n/${this.$['router/title']}`] || this.$['router/title'] || '';
16-
}
17-
18-
renderCallback() {
19-
this.sub('app/currentLang', () => this.setTitle());
20-
this.sub('router/title', () => this.setTitle());
21-
this.sub('router/route', (route) => {
22-
this.$.sectionHtml = /*html*/ `<${route}-section></${route}-section>`;
23-
}, false);
24-
}
2521
}
2622

2723
AppShell.rootStyles = styles;

components/app-shell/template.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ export default html`
66
<img src="https://rnd-pro.com/svg/symbiote/index.svg" alt="Symbiote.js" width="36">
77
<span ${{textContent: 'app/appTitle'}}></span>
88
</div>
9-
<span ${{textContent: 'sectionTitle'}}></span>
9+
<span ${{textContent: '+sectionTitle'}}></span>
1010
<select ${{onchange: 'changeLang'}}>
1111
<option value="en">English</option>
1212
<option value="es">Español</option>
1313
<option value="ru">Русский</option>
1414
</select>
1515
</header>
1616
<nav-menu></nav-menu>
17-
<main ${{innerHTML: 'sectionHtml'}}></main>
17+
<main ${{innerHTML: '+sectionHtml'}}></main>
1818
<footer>
1919
<span>&copy; ${new Date().getFullYear()}</span>
2020
<a href="https://rnd-pro.com" target="_blank">rnd-pro.com</a>

0 commit comments

Comments
 (0)