优化属性定义, 支持深层代理

master 1.10.6
yutent 2023-09-04 14:10:57 +08:00
parent 2aa9ab5af0
commit 0483d6efc3
2 changed files with 11 additions and 3 deletions

View File

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

View File

@ -201,12 +201,20 @@ export class Component extends HTMLElement {
#createProxy(name, options, newValue) {
return new Proxy(newValue || options.default, {
set: (target, prop, value) => {
get: (target, prop, receiver) => {
let value = Reflect.get(target, prop, receiver)
// 当访问的值是对象时,需要对这个对象也进行代理
if (typeof value === 'object') {
return this.#createProxy(value)
}
return value
},
set: (target, prop, value, receiver) => {
if (prop === 'length' && options.type === Array) {
return true
}
let oldValue = target[prop]
target[prop] = value
Reflect.set(target, key, value, receiver)
this.$requestUpdate(name)
if (options.observer) {