Disposable¶
Overview¶
A base class to help with managing disposal. Creates a disposeEmitter that will be fired when disposing. This occurs AFTER all prototype dispose() methods have been called up the hierarchy, so be aware of potential disposal order issues if using disposeEmitter and dispose() logic together.
This class also includes a public flag set to true when disposed.
You can also opt into asserting out when disposing, preventing disposal on your class, see Disposable.isDisposable
@author Sam Reid (PhET Interactive Simulations) @author Michael Kauzmann (PhET Interactive Simulations)
Class Disposable¶
Constructor¶
new Disposable( providedOptions? : DisposableOptions )¶
Instance Methods¶
getDisposeEmitter() : TReadOnlyEmitter¶
initializeDisposable( options? : DisposableOptions )¶
addDisposable( ...disposables : HasDispose[] )¶
Add disposables that will be disposed when this instance is disposed.
dispose()¶
addDisposerAction( disposerActionType : DisposerActionType, target : IntentionalAny, disposer : Disposer, unregisterAction : () => void )¶
Adds an action for the target to the disposeEmitter for the given disposer, so that when the disposer is disposed, the unregisterAction related to this instance is also called. For instance, the unregisterAction would be the corresponding removal/unlink/removeInputListener. It is assumed that the target and unregisterAction are related to the memory management of this instance.
removeDisposerAction( disposerActionType : DisposerActionType, target : IntentionalAny )¶
Remove the target on the disposer's disposeEmitter. This will not call the unregistration.
removeAllDisposerActions( disposerActionType : DisposerActionType )¶
Remove all disposer actions for a given type
Static Methods¶
assertNotDisposable()¶
Type DisposableOptions¶
Used in subclasses to support mutate.
- isDisposable?: boolean
Source Code¶
See the source for Disposable.ts in the axon repository.