From 32650f4b84788418159ee771062e4a376beb8b92 Mon Sep 17 00:00:00 2001 From: eavichay Date: Mon, 2 Jan 2017 13:51:53 +0200 Subject: [PATCH] adding s-resource loader --- framework/components/basic-elements.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/framework/components/basic-elements.js b/framework/components/basic-elements.js index 5301368..21932c7 100644 --- a/framework/components/basic-elements.js +++ b/framework/components/basic-elements.js @@ -140,6 +140,16 @@ Slim.tag('s-resource', class extends Slim { this.isLoading = false } + handleError(err) { + let fnName = this.onerror || this.getAttribute('onerror') + if (typeof fnName === 'function') { + fnName(err) + } else if (typeof this._boundParent[fnName] === 'function') { + this._boundParent[fnName](err) + } + this.isLoading = false + } + load() { this.isLoading = true if (this.url) { @@ -155,6 +165,9 @@ Slim.tag('s-resource', class extends Slim { this.data = data return this.data }) + .catch( err => { + this.handleError(err) + }) } }