{"version":3,"file":"ngx-property-watch-decorator.mjs","sources":["../../../projects/ngx-property-watch-decorator/src/lib/property-watch-decorator.ts","../../../projects/ngx-property-watch-decorator/src/public-api.ts","../../../projects/ngx-property-watch-decorator/src/ngx-property-watch-decorator.ts"],"sourcesContent":["export interface SimpleChange<T> {\r\n  firstChange: boolean;\r\n  previousValue: T;\r\n  currentValue: T;\r\n  isFirstChange: () => boolean;\r\n}\r\n\r\nexport type CallBackFunction<T> = (value: T, change?: SimpleChange<T>) => void;\r\n\r\nexport function OnChange<T = any>(callback: CallBackFunction<T> | string) {\r\n\r\n  const cachedValueKey = Symbol();\r\n  const isFirstChangeKey = Symbol();\r\n\r\n  return (target: any, key: PropertyKey) => {\r\n\r\n    const callBackFn: CallBackFunction<T> = typeof callback === 'string' ? target[callback] : callback;\r\n\r\n    if (!callBackFn) {\r\n      throw new Error(`Cannot find method ${callback} in class ${target.constructor.name}`);\r\n    }\r\n\r\n    Object.defineProperty(target, key, {\r\n      set: function (value) {\r\n\r\n        // change status of \"isFirstChange\"\r\n        this[isFirstChangeKey] = this[isFirstChangeKey] === undefined;\r\n\r\n        // No operation if new value is same as old value\r\n        if (!this[isFirstChangeKey] && this[cachedValueKey] === value) {\r\n          return;\r\n        }\r\n\r\n        const oldValue = this[cachedValueKey];\r\n        this[cachedValueKey] = value;\r\n        const simpleChange: SimpleChange<T> = {\r\n          firstChange: this[isFirstChangeKey],\r\n          previousValue: oldValue,\r\n          currentValue: this[cachedValueKey],\r\n          isFirstChange: () => this[isFirstChangeKey],\r\n        };\r\n        callBackFn.call(this, this[cachedValueKey], simpleChange);\r\n      },\r\n      get: function () {\r\n        return this[cachedValueKey];\r\n      },\r\n    });\r\n  };\r\n}\r\n","/*\n * Public API Surface of ngx-property-watch-decorator\n */\n\nexport * from './lib/property-watch-decorator';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AASM,SAAU,QAAQ,CAAU,QAAsC,EAAA;AAEtE,I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