Error check in case of multiple nodes generated

This commit is contained in:
Tony Garnock-Jones 2023-12-02 19:35:36 +01:00
parent cfd2b69943
commit ae2c113325
1 changed files with 8 additions and 1 deletions

View File

@ -39,7 +39,14 @@ export class Widget implements EventTarget {
dataflow {
const oldNode = this.node.value;
const newNode = template`${this.nodeGenerator(template)}`.node();
const fragments = template`${this.nodeGenerator(template)}`;
const newNodes = fragments.nodes();
if (newNodes.length > 1) {
throw new Error(`@syndicate-lang/html2: Multiple nodes returned from template: ${fragments.toString()}`);
}
const newNode = newNodes[0];
if (oldNode !== newNode) {
if (oldNode !== null) {
for (const [type, cbs] of this.callbacks.entries()) {