• value: either the initial value, the value the Promise resolved to, or the value the Promise was rejected with. use .state if you need to be able to tell the difference.
    • state: one of "pending", "fulfilled" or "rejected"

    And the following methods:

    • case({fulfilled, rejected, pending}): maps over the result using the provided handlers, or returns undefined if a handler isn’t available for the current promise state.
    • then((value: TValue) => TResult1 | PromiseLike<TResult1>, [(rejectReason: any) => any]): chains additional handlers to the provided promise.

    Note that the status strings are available as constants: mobxUtils.PENDING, mobxUtils.REJECTED, mobxUtil.FULFILLED

    • IThenable<T> The promise which will be observed
    • oldPromise IThenable<T> ? The promise which will be observed

    Examples

    1. const fetchResult = fromPromise(fetch("http://someurl"))
    2. // combine with when..
    3. when(
    4. () => fetchResult.state !== "pending",
    5. () => {
    6. }
    7. )
    8. // or a mobx-react component..
    9. const myComponent = observer(({ fetchResult }) => {
    10. switch(fetchResult.state) {
    11. case "pending": return <div>Loading...</div>
    12. case "rejected": return <div>Ooops... {fetchResult.value}</div>
    13. case "fulfilled": return <div>Gotcha: {fetchResult.value}</div>
    14. }
    15. // or using the case method instead of switch:
    16. fetchResult.case({
    17. pending: () => <div>Loading...</div>,
    18. rejected: error => <div>Ooops.. {error}</div>,
    19. fulfilled: value => <div>Gotcha: {value}</div>,
    20. }))
    21. // chain additional handler(s) to the resolve/reject:
    22. fetchResult.then(
    23. (result) => doSomeTransformation(result),
    24. (rejectReason) => console.error('fetchResult was rejected, reason: ' + rejectReason)
    25. ).then(
    26. (transformedResult) => console.log('transformed fetchResult: ' + transformedResult)
    27. )

    Returns IPromiseBasedObservable<T>