* Add Actions to ViewModel utility types and specify `this: void` signature Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add https://typescript-eslint.io/rules/unbound-method/ linter to shared-components also fix stray lint config which doesn't apply to SC Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add https://typescript-eslint.io/rules/unbound-method/ linter to element-web Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix genuine issues identified by the linter Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Specify this:void on i18napi Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update Module API Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Add comment for MapToVoidThis Added utility type to map VM actions to unbound functions. --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
22 lines
733 B
TypeScript
22 lines
733 B
TypeScript
/*
|
|
Copyright 2025 New Vector Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import { useSyncExternalStore } from "react";
|
|
|
|
import { type ViewModel } from "./ViewModel";
|
|
|
|
/**
|
|
* A small wrapper around useSyncExternalStore to use a view model in a shared component view
|
|
* @param vm The view model to use
|
|
* @returns The current snapshot
|
|
*/
|
|
export function useViewModel<T>(vm: ViewModel<T, unknown>): T {
|
|
// We need to pass the same getSnapshot function as getServerSnapshot as this
|
|
// is used when making the HTML chat export.
|
|
return useSyncExternalStore(vm.subscribe, vm.getSnapshot, vm.getSnapshot);
|
|
}
|