Skip to content

Commit e66ad6c

Browse files
committed
remove cache, only swap when needed
1 parent 12a6526 commit e66ad6c

File tree

2 files changed

+1763
-1776
lines changed

2 files changed

+1763
-1776
lines changed

lit-element-router.js

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export function outlet(base) {
187187
return class extends base {
188188
static get properties() {
189189
return {
190-
activeRoute: { type: String, reflect: true, attribute: "active-route" }
190+
activeRoute: { type: String, reflect: true, attribute: "active-route" },
191191
};
192192
}
193193

@@ -217,42 +217,34 @@ export function outlet(base) {
217217
}
218218

219219
outlet() {
220-
const nodeCache = {};
221220
Array.from(this.querySelectorAll(`[route]`)).map((active) => {
222-
const name = active.getAttribute("route");
223-
const template = nodeCache[name] || this.moveChildNodes(active);
224-
nodeCache[name] = template;
225-
// replace route by template
226-
active.replaceWith(template);
221+
if (active.tagName !== "TEMPLATE") {
222+
const template = this.moveChildNodes(active);
223+
active.replaceWith(template);
224+
}
227225
});
228226
if (this.shadowRoot) {
229227
Array.from(this.shadowRoot.querySelectorAll(`[route]`)).map(
230228
(active) => {
231-
const name = active.getAttribute("route");
232-
const template = nodeCache[name] || this.moveChildNodes(active);
233-
nodeCache[name] = template;
234-
235-
// replace route by template
236-
active.replaceWith(template);
229+
if (active.tagName !== "TEMPLATE") {
230+
const template = this.moveChildNodes(active);
231+
active.replaceWith(template);
232+
}
237233
}
238234
);
239235
}
240236
if (this.activeRoute) {
241237
Array.from(this.querySelectorAll(`[route~=${this.activeRoute}]`)).map(
242238
(active) => {
243-
const name = active.getAttribute("route");
244-
const template = nodeCache[name];
245-
const dom = this.moveChildNodes(template, "div");
239+
const dom = this.moveChildNodes(active, "div");
246240
active.replaceWith(dom);
247241
}
248242
);
249243
if (this.shadowRoot) {
250244
Array.from(
251245
this.shadowRoot.querySelectorAll(`[route~=${this.activeRoute}]`)
252246
).map((active) => {
253-
const name = active.getAttribute("route");
254-
const template = nodeCache[name];
255-
const dom = this.moveChildNodes(template, "div");
247+
const dom = this.moveChildNodes(active, "div");
256248
active.replaceWith(dom);
257249
});
258250
}

0 commit comments

Comments
 (0)