Skip to content

Commit

Permalink
fix(sifrr-tempalte): small bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aadityataparia committed Jan 21, 2020
1 parent 1a3f326 commit 3ce4879
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/browser/sifrr-dom/src/dom/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function elementClassFactory(baseClass: typeof HTMLElement) {
onStateChange() {}

update() {
if (!this.connected) return;
this.beforeUpdate();
update(this.__content, this);
trigger(this, 'update', { detail: { state: this.state } });
Expand Down
1 change: 1 addition & 0 deletions packages/browser/sifrr-template/src/template/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const createTemplate = <T>(
} else if (!Array.isArray(oldValue)) {
console.warn(`oldValue given to Component function was not an Array.
template: \`${String.raw(str, ...substitutions)}\``);
} else if (oldValue.length == 1 && oldValue[0].nodeType === TEXT_NODE) {
} else if (oldValue.length > 0) {
console.warn(`oldValue given to Component function was not created by this Component.
This might be a bug or caused if you return different
Expand Down
17 changes: 12 additions & 5 deletions packages/browser/sifrr-template/src/template/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function update<T>(
const hasOnPropChange = typeof (<SifrrNode<any>>node).onPropChange === 'function';
const hasUpdate = typeof (<SifrrNode<any>>node).update === 'function';

let promise = false;
for (let j = bindMap.length - 1; j > -1; --j) {
const binding = bindMap[j];

Expand All @@ -48,20 +49,22 @@ export default function update<T>(

const oldValue = currentValues[j];
if (oldValue instanceof Promise) {
currentValues[j] = oldValue.then(oldValue => {
let newValue = binding.value(props, oldValue);
promise = true;
currentValues[j] = oldValue.then(oldv => {
let newValue = binding.value(props, oldv);

if (newValue instanceof Promise) {
return newValue.then(nv => updateOne(node, binding, oldValue, nv, hasOnPropChange));
return newValue.then(nv => updateOne(node, binding, oldv, nv, hasOnPropChange));
} else {
return updateOne(node, binding, oldValue, newValue, hasOnPropChange);
return updateOne(node, binding, oldv, newValue, hasOnPropChange);
}
});
} else {
const oldValue = currentValues[j];
let newValue = binding.value(props, oldValue);

if (newValue instanceof Promise) {
promise = true;
currentValues[j] = newValue.then(nv =>
updateOne(node, binding, oldValue, nv, hasOnPropChange)
);
Expand All @@ -70,7 +73,11 @@ export default function update<T>(
}
}
}
hasUpdate && Promise.all(currentValues).then(() => (<SifrrNode<any>>node).update());
if (hasUpdate) {
promise
? Promise.all(currentValues).then(() => (<SifrrNode<any>>node).update())
: (<SifrrNode<any>>node).update();
}
}
}

Expand Down

0 comments on commit 3ce4879

Please sign in to comment.