props增加异常打印

master
yutent 2023-11-23 17:42:00 +08:00
parent 47090149f8
commit bbe04eae83
2 changed files with 11 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "wkit", "name": "wkit",
"version": "1.11.0", "version": "1.11.1",
"type": "module", "type": "module",
"description": "A library for building fast, lightweight web components.", "description": "A library for building fast, lightweight web components.",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -31,6 +31,14 @@ export {
} from './utils.js' } from './utils.js'
export { html, raw, css, svg, bind, unbind, nextTick, fire, hyphen, camelize } 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 = {}) { export function classMap(data = {}) {
let output = '' let output = ''
@ -196,9 +204,7 @@ export class Component extends HTMLElement {
} }
this[key] = value this[key] = value
this.$requestUpdate(name) this.$requestUpdate(name)
if (options.observer) { safely.call(this, options.observer, value, oldValue)
options.observer.call(this, value, oldValue)
}
} }
} }
this[key] = options.default this[key] = options.default
@ -225,10 +231,7 @@ export class Component extends HTMLElement {
Reflect.set(target, prop, value, receiver) Reflect.set(target, prop, value, receiver)
this.$requestUpdate(key) this.$requestUpdate(key)
safely.call(this, options.observer, value, oldValue)
if (options.observer) {
options.observer.call(this, value, oldValue)
}
return true return true
} }
}) })