/**
 *
 * ```ts
 * @Update()
 * set myProperty() {
 *     ...
 * }
 * ```
 *
 * @public
 */
export function Update() {
    return (target, propertyName, originalDescriptor) => {
        const privatePropertyName = `$$__${propertyName.toString()}`;
        // The originalDescriptor is only set to `true` when it is a real property with get/set.
        if (!originalDescriptor) {
            if (Object.prototype.hasOwnProperty.call(target, privatePropertyName)) {
                console.warn(`[Update]: The prop '${privatePropertyName}' is already exist, it will be overridden by Update decorator.`);
            }
            Object.defineProperty(target, privatePropertyName, {
                configurable: true,
                writable: true
            });
        }
        return {
            get() {
                const current = originalDescriptor?.get
                    ? originalDescriptor.get.bind(this)()
                    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
                    // @ts-ignore
                    : this[privatePropertyName];
                return current;
            },
            set(value) {
                if (originalDescriptor?.set) {
                    originalDescriptor.set.bind(this)(value);
                }
                else {
                    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
                    // @ts-ignore
                    this[privatePropertyName] = value;
                }
                this.requestUpdate(privatePropertyName);
            }
        };
    };
}
//# sourceMappingURL=UpdateDecorator.js.map