export interface SimpleChange < T > { firstChange : boolean ; previousValue : T ; currentValue : T ; isFirstChange : ( ) => boolean ; } export function OnChange < T = any > ( callback = 'nglOnPropertyChange' ) { const cachedValueKey = Symbol ( ) ; const isFirstChangeKey = Symbol ( ) ; return ( target , key ) => { Object . defineProperty ( target , key , { set : function ( value ) { if ( this [ isFirstChangeKey ] === undefined ) { this [ isFirstChangeKey ] = true ; } else { this [ isFirstChangeKey ] = false ; } if ( ! this [ isFirstChangeKey ] && this [ cachedValueKey ] === value ) { return ; } const oldValue = this [ cachedValueKey ] ; this [ cachedValueKey ] = value ; const simpleChange = { firstChange : this [ isFirstChangeKey ] , previousValue : oldValue , currentValue : this [ cachedValueKey ] , isFirstChange : ( ) => this [ isFirstChangeKey ] , } ; this [ callback ] ( key , this [ cachedValueKey ] , simpleChange ) ; } , get : function ( ) { return this [ cachedValueKey ] ; } , } ) ; } ; }