import { dispatchChange } from '../internals/ChangeDispatcher'; export interface WatchNumberOptions { name: Key; } export type WatchNumberDecorated = { [key in Key]: number; }; type WatchNumberDecoratedInt = { [key in KeyInt]: number; }; export const WatchNumber = (options: WatchNumberOptions) => { const name = options.name; return function (objOrCls: WatchNumberDecorated, propertyKey: KeyInt) { Object.defineProperties(objOrCls, { [name]: { get: function (this: WatchNumberDecorated & WatchNumberDecoratedInt): number { return this[propertyKey]; }, set: function (this: WatchNumberDecorated & WatchNumberDecoratedInt, value: number) { value = Number(value); const oldValue = this[propertyKey]; if (oldValue !== value) { Reflect.set(this, propertyKey, value); dispatchChange(this, name, oldValue, this[propertyKey]); } }, }, }); }; };