import { dispatchChange } from '../internals/ChangeDispatcher'; export interface WatchBooleanOptions { name: Key; } export type WatchBooleanDecorated = { [key in Key]: boolean; }; type WatchBooleanDecoratedInt = { [key in KeyInt]: boolean; }; export const WatchBoolean = (options: WatchBooleanOptions) => { const name = options.name; return function (objOrCls: WatchBooleanDecorated, propertyKey: KeyInt) { Object.defineProperties(objOrCls, { [name]: { get: function (this: WatchBooleanDecorated & WatchBooleanDecoratedInt): boolean { return this[propertyKey]; }, set: function (this: WatchBooleanDecorated & WatchBooleanDecoratedInt, value: boolean) { value = Boolean(value); const oldValue = this[propertyKey]; if (oldValue !== value) { Reflect.set(this, propertyKey, value); dispatchChange(this, name, oldValue, this[propertyKey]); } }, }, }); }; };