Skip to content

Latest commit

 

History

History
77 lines (60 loc) · 2.87 KB

Lifecycle_in_Depth.md

File metadata and controls

77 lines (60 loc) · 2.87 KB

Lifecycle in Depth

RASCL then tracks the "lifecycle" of each API call as a finite state machine. As the API call "moves" through the lifecycle, each stage dispatches a Redux action containing the relevant data.

RASCL State Diagram An API endpoint's state transitions

Starting Conditions

INITIAL
This is the starting state for all endpoints. An endpoint at INITIAL has not been used. No API calls have been made, no actions have been dispatched, and all data fields will still be null.

Making Requests

ENQUEUE (Optional)
The optional ENQUEUE state allows for common utility patterns. An "offline-first" webapp may want to allow enqueueing multiple requests while offline, or a modal login window may be rendered over the application, which has UI logic that makes API calls as soon as possible after rendering. In either case, ENQUEUE allows a developer to create preconditions for certain calls, for instance to say "only make this call once the device is online and the user has valid credentials".
REQUEST
An endpoint is set to the REQUEST state after the API request has been made, but before any response has come back. This will set isFetching true`, which is useful for triggering spinners or blocking user actions while awaiting data.

Handling Data

SUCCESS
Indicates a 2XX response from the API. May or may not include a body.

Recovering From Errors

FAILURE
Usually indicates a 4XX response from the API.
MISTAKE
Indicates a 5XX response from the API.

Resolving Warnings

OFFLINE
Indicates that the device is offline, or otherwise has no internet connection.
TIMEOUT
Indicates that the request was sent, but that the response didn't arrive in a specific timeframe.