mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-22 20:46:38 +08:00
feat(infra): remove obsolete pattern (#11177)
React suspense is a deprecated mode, remove the useEnsureLiveData method
This commit is contained in:
@@ -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>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user