react-async-states icon indicating copy to clipboard operation
react-async-states copied to clipboard

enhance the read api support + suspense and error boundary

Open incepter opened this issue 2 years ago • 0 comments

The read api should allow to specify whether to suspend on initial status, and also whether to throw on error status.

function read(suspendingStatuses, throwingStatuses) {
if (suspendingStatuses[currentState.status]) throw suspender; // promise
if (suspendingStatuses[currentState.status]) throw selector(currentState.data); // or may br throw state.data ? or even make it configurable ?
return selector(state, lastSuccess, cache);
}


const state  = read({initial: true, pending: false}, {error: true, aborted: true });

// rules:
// no state should be truthy in both parameters
// doesn't care if you have suspense or error boundary up in the tree, if you suspend, you need suspense, if you throw on error, you need error boundary

incepter avatar Apr 26 '22 02:04 incepter