license import { PropertyValues , ReactiveElement } from '@lit/reactive-element' ; /**
 * Observer function type.
 */ export interface Observer { ( value , old ) : void ; } type ReactiveElementClass = typeof ReactiveElement ; interface ReactiveElementClassWithObservers extends ReactiveElementClass { _observers : Map < PropertyKey , Observer > ; } /**
 * Specifies an observer callback that is run when the decorated property
 * changes. The observer receives the current and old value as arguments.
 */ export const observer = ( observer ) => ( proto , propName ) => { if ( ! ( proto . constructor as ReactiveElementClassWithObservers ) . _observers ) { proto . constructor . _observers = new Map < PropertyKey , Observer > ( ) ; const userUpdated = proto . updated ; proto . updated = function ( this , changedProperties ) { userUpdated . call ( this , changedProperties ) ; changedProperties . forEach ( ( v , k ) => { const observers = ( this . constructor as ReactiveElementClassWithObservers ) . _observers ; const observer = observers . get ( k ) ; if ( observer !== undefined ) { observer . call ( this , ( this as any ) [ k ] , v ) ; } } ) ; } ; } else if ( ! proto . constructor . hasOwnProperty ( '_observers' ) ) { const observers = proto . constructor . _observers ; proto . constructor . _observers = new Map ( ) ; observers . forEach ( ( v , k ) => proto . constructor . _observers . set ( k , v ) ) ; } proto . constructor . _observers . set ( propName , observer ) ; } ;