forked from mystiq/hydrogen-web
show errors while mounting list view children
This commit is contained in:
parent
762ed96a3b
commit
2e34668b91
2 changed files with 11 additions and 3 deletions
|
@ -15,6 +15,7 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {tag} from "./html.js";
|
import {tag} from "./html.js";
|
||||||
|
import {errorToDOM} from "./error.js";
|
||||||
|
|
||||||
function insertAt(parentNode, idx, childNode) {
|
function insertAt(parentNode, idx, childNode) {
|
||||||
const isLast = idx === parentNode.childElementCount;
|
const isLast = idx === parentNode.childElementCount;
|
||||||
|
@ -106,8 +107,12 @@ export class ListView {
|
||||||
for (let item of this._list) {
|
for (let item of this._list) {
|
||||||
const child = this._childCreator(item);
|
const child = this._childCreator(item);
|
||||||
this._childInstances.push(child);
|
this._childInstances.push(child);
|
||||||
|
try {
|
||||||
const childDomNode = child.mount(this._mountArgs);
|
const childDomNode = child.mount(this._mountArgs);
|
||||||
fragment.appendChild(childDomNode);
|
fragment.appendChild(childDomNode);
|
||||||
|
} catch (err) {
|
||||||
|
fragment.appendChild(errorToDOM(err));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this._root.appendChild(fragment);
|
this._root.appendChild(fragment);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,10 @@ import {tag} from "./html.js";
|
||||||
|
|
||||||
export function errorToDOM(error) {
|
export function errorToDOM(error) {
|
||||||
const stack = new Error().stack;
|
const stack = new Error().stack;
|
||||||
const callee = stack.split("\n")[1];
|
let callee = null;
|
||||||
|
if (stack) {
|
||||||
|
callee = stack.split("\n")[1];
|
||||||
|
}
|
||||||
return tag.div([
|
return tag.div([
|
||||||
tag.h2("Something went wrong…"),
|
tag.h2("Something went wrong…"),
|
||||||
tag.h3(error.message),
|
tag.h3(error.message),
|
||||||
|
|
Loading…
Reference in a new issue