mirror of
https://github.com/zhigang1992/mobx-utils.git
synced 2026-06-19 01:36:37 +08:00
Fix IBasePromiseBasedObservable
Currently, attempting to access the stale value in the pending cause will throw `Type '(staleValue: any) => Element' is not assignable to type '() => Element'`
This commit is contained in:
@@ -7,9 +7,15 @@ export const PENDING = "pending"
|
||||
export const FULFILLED = "fulfilled"
|
||||
export const REJECTED = "rejected"
|
||||
|
||||
type CaseHandlers<U, T> = {
|
||||
pending?: (t?: T) => U
|
||||
fulfilled?: (t: T) => U
|
||||
rejected?: (e: any) => U
|
||||
}
|
||||
|
||||
export type IBasePromiseBasedObservable<T> = {
|
||||
isPromiseBasedObservable: true
|
||||
case<U>(handlers: { pending?: () => U; fulfilled?: (t: T) => U; rejected?: (e: any) => U }, defaultFulfilled?: boolean): U
|
||||
case<U>(handlers: CaseHandlers<U, T>, defaultFulfilled?: boolean): U
|
||||
} & PromiseLike<T>
|
||||
|
||||
export type IPendingPromise = {
|
||||
@@ -30,11 +36,7 @@ export type IRejectedPromise = {
|
||||
export type IPromiseBasedObservable<T> = IBasePromiseBasedObservable<T> &
|
||||
(IPendingPromise | IFulfilledPromise<T> | IRejectedPromise)
|
||||
|
||||
function caseImpl<U, T>(handlers: {
|
||||
pending?: (t?: T) => U
|
||||
fulfilled?: (t: T) => U
|
||||
rejected?: (e: any) => U
|
||||
}): U {
|
||||
function caseImpl<U, T>(handlers: CaseHandlers<U, T>): U {
|
||||
switch (this.state) {
|
||||
case PENDING:
|
||||
return handlers.pending && handlers.pending(this.value)
|
||||
|
||||
Reference in New Issue
Block a user