Skip to content

Commit 2ff99ad

Browse files
committed
Create a proper DeviceViewport interface
1 parent b396374 commit 2ff99ad

1 file changed

Lines changed: 17 additions & 19 deletions

File tree

src/webflo-runtime/webflo-client/DeviceViewport.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ export class DeviceViewport {
7373

7474
// 1. Handle Title
7575
if ('title' in state) {
76-
document.title = state.title || '';
76+
const val = state.title || '';
77+
if (document.title !== val) {
78+
document.title = val;
79+
}
7780
activeKeys.delete('title');
7881
}
7982

@@ -118,27 +121,20 @@ export class DeviceViewport {
118121
});
119122

120123
const vContent = viewportDirectives.join(', ');
121-
const vEl = this.#elements.viewport || (vContent ? this.#getOrCreate('viewport') : null);
122-
if (vEl) {
123-
vEl.setAttribute('content', vContent);
124-
if (!vContent && this.#ownedElements.has(vEl)) {
125-
vEl.remove();
126-
delete this.#elements.viewport;
127-
}
128-
}
124+
this.#setAttr('viewport', vContent);
129125
}
130126

131-
#setAttr(jsKey, val, media = null) {
132-
const cacheKey = media ? `${jsKey}-${media}` : jsKey;
127+
#setAttr(jsKey, val, media = '') {
133128
const config = this.#specials[jsKey];
134-
const attrName = config.type === 'link' ? 'href' : 'content';
129+
const attrName = config?.type === 'link' ? 'href' : 'content';
135130

136131
if (val !== undefined && val !== null) {
137132
const el = this.#getOrCreate(jsKey, media);
138133
if (el.getAttribute(attrName) !== val) {
139134
el.setAttribute(attrName, val);
140135
}
141136
} else {
137+
const cacheKey = media ? `${jsKey}-${media}` : jsKey;
142138
const el = this.#elements[cacheKey];
143139
if (el) {
144140
if (this.#ownedElements.has(el)) {
@@ -163,13 +159,15 @@ export class DeviceViewport {
163159
this.#scheduleRender();
164160
}
165161

166-
pop(id) {
167-
if (!id) throw new Error("pop() requires a target ID");
168-
const idx = this.#stack.findIndex(e => e.id === id);
169-
if (idx > 0) { // Never pop the initial state at index 0
170-
this.#stack.splice(idx, 1);
171-
this.#scheduleRender();
172-
}
162+
pop(...ids) {
163+
if (!ids.length) throw new Error("pop() requires a target ID");
164+
ids.forEach((id) => {
165+
const idx = this.#stack.findIndex(e => e.id === id);
166+
if (idx > 0) { // Never pop the initial state at index 0
167+
this.#stack.splice(idx, 1);
168+
}
169+
});
170+
this.#scheduleRender();
173171
}
174172

175173
peek() { return this.#stack[this.#stack.length - 1]; }

0 commit comments

Comments
 (0)