Skip to content

Commit 2cdc096

Browse files
committed
Add priority support to viewport.push()
1 parent 1979776 commit 2cdc096

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class DeviceViewport {
1313
};
1414

1515
constructor() {
16-
const initialState = { _isInitial: true };
16+
const initialState = { _priority: 1 };
1717

1818
// 1. Ingest Viewport
1919
const vMeta = document.querySelector('meta[name="viewport"]');
@@ -152,10 +152,17 @@ export class DeviceViewport {
152152
return [k.replace(/-([a-z])/g, g => g[1].toUpperCase()), v || true];
153153
}));
154154

155-
push(id, config) {
155+
push(id, config, priority = 1) {
156156
if (!id) throw new Error("push() requires a unique ID");
157157
if (this.#stack.some(e => e.id === id)) return;
158-
this.#stack.push({ ...this.peek(), ...config, id, _isInitial: false });
158+
159+
const peek = this.peek();
160+
if (peek._priority - priority >= 0.2) {
161+
this.#stack.push({ ...config, ...peek, id, _priority: priority });
162+
} else {
163+
this.#stack.push({ ...peek, ...config, id, _priority: priority });
164+
}
165+
159166
this.#scheduleRender();
160167
}
161168

0 commit comments

Comments
 (0)