diff --git a/package.json b/package.json index 727573a..b05fcd6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wkit", - "version": "1.11.0", + "version": "1.11.1", "type": "module", "description": "A library for building fast, lightweight web components.", "main": "dist/index.js", diff --git a/src/index.js b/src/index.js index c110ec4..c1a92ce 100644 --- a/src/index.js +++ b/src/index.js @@ -31,6 +31,14 @@ export { } from './utils.js' export { html, raw, css, svg, bind, unbind, nextTick, fire, hyphen, camelize } +function safely(callback, ...args) { + try { + callback && callback.apply(this, args) + } catch (err) { + console.error(err) + } +} + // 简单的类名解析 export function classMap(data = {}) { let output = '' @@ -196,9 +204,7 @@ export class Component extends HTMLElement { } this[key] = value this.$requestUpdate(name) - if (options.observer) { - options.observer.call(this, value, oldValue) - } + safely.call(this, options.observer, value, oldValue) } } this[key] = options.default @@ -225,10 +231,7 @@ export class Component extends HTMLElement { Reflect.set(target, prop, value, receiver) this.$requestUpdate(key) - - if (options.observer) { - options.observer.call(this, value, oldValue) - } + safely.call(this, options.observer, value, oldValue) return true } })