-
Notifications
You must be signed in to change notification settings - Fork 8
/
TReadOnlyProperty.ts
32 lines (28 loc) · 1.3 KB
/
TReadOnlyProperty.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright 2021-2022, University of Colorado Boulder
import { LinkOptions } from './ReadOnlyProperty.js';
/**
* A simple read-only Property/TinyProperty-like interface
*
* @author Sam Reid (PhET Interactive Simulations)
* @author Jonathan Olson <[email protected]>
*/
export type PropertyLinkListener<T> = ( value: T, oldValue: T | null, tinyProperty: TReadOnlyProperty<T> ) => void;
export type PropertyLazyLinkListener<T> = ( value: T, oldValue: T, tinyProperty: TReadOnlyProperty<T> ) => void;
export type PropertyListener<T> = PropertyLinkListener<T> | PropertyLazyLinkListener<T>;
// See comments in Property.ts / TinyProperty.ts
type TReadOnlyProperty<T> = {
get: () => T;
get value(): T;
areValuesEqual( a: T, b: T ): boolean;
link( listener: PropertyLinkListener<T>, options?: LinkOptions ): void;
lazyLink( listener: PropertyLazyLinkListener<T>, options?: LinkOptions ): void;
linkAttribute<Attr extends string>( object: { [key in Attr]: T }, attributeName: Attr ): any; // eslint-disable-line
unlink( listener: PropertyListener<T> ): void;
unlinkAll(): void;
unlinkAttribute( listener: PropertyLinkListener<T> ): void;
hasListener( listener: PropertyLinkListener<T> ): boolean;
isSettable(): boolean;
dispose(): void;
isDisposed?: boolean;
};
export default TReadOnlyProperty;