feat: animate completed items out
This commit is contained in:
@@ -227,13 +227,15 @@ export async function runLatestRequest<T>(
|
||||
return committed
|
||||
}
|
||||
|
||||
type MutationSuccessCallback<T> = (value: T) => void | Promise<void>
|
||||
|
||||
export type MutationReconciler<TContext> = {
|
||||
run<T>(
|
||||
mutation: () => Promise<T>,
|
||||
onSuccess: (value: T) => void,
|
||||
onError?: (reason: unknown) => void,
|
||||
onCurrentSuccess?: (value: T) => void,
|
||||
): Promise<void>
|
||||
onCurrentSuccess?: MutationSuccessCallback<T>,
|
||||
): Promise<boolean>
|
||||
}
|
||||
|
||||
export function createMutationReconciler<TContext>(
|
||||
@@ -269,12 +271,16 @@ export function createMutationReconciler<TContext>(
|
||||
value = await mutation()
|
||||
} catch (reason) {
|
||||
onError?.(reason)
|
||||
return
|
||||
return false
|
||||
}
|
||||
onSuccess(value)
|
||||
if (sameContext(context, currentContext())) onCurrentSuccess?.(value)
|
||||
if (sameContext(context, currentContext())) {
|
||||
const currentSuccess = onCurrentSuccess?.(value)
|
||||
if (currentSuccess instanceof Promise) await currentSuccess
|
||||
}
|
||||
await reconcile(context)
|
||||
if (sameContext(context, currentContext()) && reconciled < dirty) await reconcile(context)
|
||||
return true
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user