Skip to content

Commit a48d308

Browse files
committed
Use disposable in BaseViewModel
1 parent 809ab58 commit a48d308

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/viewmodels/base/BaseViewModel.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ Please see LICENSE files in the repository root for full details.
66
*/
77

88
import { type ViewModel } from "../../shared-components/ViewModel";
9+
import { Disposables } from "./Disposables";
910
import { Snapshot } from "./Snapshot";
1011
import { ViewModelSubscriptions } from "./ViewModelSubscriptions";
1112

1213
export abstract class BaseViewModel<T, P> implements ViewModel<T> {
1314
protected subs: ViewModelSubscriptions;
1415
protected snapshot: Snapshot<T>;
1516
protected props: P;
17+
protected disposables = new Disposables();
1618

1719
protected constructor(props: P, initialSnapshot: T) {
1820
this.props = props;
@@ -32,4 +34,11 @@ export abstract class BaseViewModel<T, P> implements ViewModel<T> {
3234
public getSnapshot = (): T => {
3335
return this.snapshot.current;
3436
};
37+
38+
/**
39+
* Relinquish any resources held by this view-model.
40+
*/
41+
public dispose(): void {
42+
this.disposables.dispose();
43+
}
3544
}

0 commit comments

Comments
 (0)