mirror of
https://github.com/vector-im/element-call.git
synced 2026-07-03 18:12:58 +00:00
Require ObservableScopes of state holders to be specified explicitly
Previously we had a ViewModel class which was responsible for little more than creating an ObservableScope. However, since this ObservableScope would be created implicitly upon view model construction, it became a tad bit harder for callers to remember to eventually end the scope (as you wouldn't just have to remember to end ObservableScopes, but also to destroy ViewModels). Requiring the scope to be specified explicitly by the caller also makes it possible for the caller to reuse the scope for other purposes, reducing the number of scopes mentally in flight that need tending to, and for all state holders (not just view models) to be handled uniformly by helper functions such as generateKeyed$.
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
Copyright 2023, 2024 New Vector Ltd.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { ObservableScope } from "./ObservableScope";
|
||||
|
||||
/**
|
||||
* An MVVM view model.
|
||||
*/
|
||||
export abstract class ViewModel {
|
||||
protected readonly scope = new ObservableScope();
|
||||
|
||||
/**
|
||||
* Instructs the ViewModel to clean up its resources. If you forget to call
|
||||
* this, there may be memory leaks!
|
||||
*/
|
||||
public destroy(): void {
|
||||
this.scope.end();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user