feat(infra): remove obsolete pattern (#11177)

React suspense is a deprecated mode, remove the useEnsureLiveData method
This commit is contained in:
EYHN
2025-03-25 13:20:17 +00:00
parent ad4e1ed7de
commit d7567edcb8
5 changed files with 29 additions and 62 deletions
+1 -1
View File
@@ -10,4 +10,4 @@ export {
onStart,
smartRetry,
} from './ops';
export { useEnsureLiveData, useLiveData } from './react';
export { useLiveData } from './react';
@@ -1,4 +1,3 @@
import { use } from 'foxact/use';
import { useSyncExternalStore } from 'react';
import type { LiveData } from './livedata';
@@ -36,33 +35,3 @@ export function useLiveData<Input extends LiveData<any> | null | undefined>(
: nullGetSnapshot
);
}
/**
* subscribe LiveData and return the value. If the value is nullish, will suspends until the value is not nullish.
*/
export function useEnsureLiveData<T>(liveData$: LiveData<T>): NonNullable<T> {
const data = useLiveData(liveData$);
if (data === null || data === undefined) {
return use(
new Promise<NonNullable<T>>((resolve, reject) => {
const subscription = liveData$.subscribe({
next(value) {
if (value !== null && value !== undefined) {
resolve(value as NonNullable<T>);
subscription.unsubscribe();
}
},
error(err) {
reject(err);
},
complete() {
reject(new Error('Unexpected completion'));
},
});
})
);
}
return data as NonNullable<T>;
}