1.0.0 • Published 6 years ago

@salsita/react-api v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

react-api

Install

Install this package with npm

npm i @salsita/react-api

or yarn

yarn add @salsita/react-api

API

Modules

Classes

Constants

Functions

ApiActions

ApiActions.apiError(errorType, errorReason) ⇒ Action

Saves API error

Kind: static method of ApiActions

ParamTypeDescription
errorTypestringType of the error
errorReasonstringReason of the error

ApiActions.startLoading() ⇒ Action

Sets the global loading indicator on

Kind: static method of ApiActions

ApiActions.stopLoading() ⇒ Action

Sets the global loading indicator off

Kind: static method of ApiActions

ApiSelectors

ApiSelectors.getError(state) ⇒ string | null

Returns the latest API error type

Kind: static method of ApiSelectors
Returns: string | null - The latest API error type

ParamTypeDescription
stateRootStateThe root state

ApiSelectors.isLoading(state) ⇒ boolean

Returns true if a loading is in progress

Kind: static method of ApiSelectors
Returns: boolean - True if a loading indicator is in progress, false otherwise

ParamTypeDescription
stateRootStateThe root state

ApiError

The base class for API errors

Kind: global class

apiError.constructor(type, reason)

Creates an API error

Kind: instance method of ApiError

ParamTypeDescription
typestringType of the error
reasonstringReason of the error

apiError.getReason() ⇒ string

Get the error reason

Kind: instance method of ApiError
Returns: string - The error reason

apiError.getType() ⇒ string

Get the error type

Kind: instance method of ApiError
Returns: string - The error type

BusinessValidationError

The class for business validation error

Kind: global class

businessValidationError.constructor(reason)

Creates a business validation error

Kind: instance method of BusinessValidationError

ParamTypeDescription
reasonstringThe error reason

HTTP_CONFLICT

The error code for HTTP conflict

Kind: global constant

apiReducer(state, action) ⇒ ApiState

The reducer of the API module

Kind: global function

ParamTypeDescription
stateApiStateThe state of the API module
actionActionA redux action

withErrorHandling(saga, ...args)

Wraps saga into try/catch block catching all the ApiErrors and translating them to API_ERROR actions.

Kind: global function

ParamTypeDescription
sagaGeneratorAPI call saga which may throw an ApiError
...argsanyArguments to be passed to the saga

withLoadingIndicator(saga, ...args)

Wraps saga into start/stop loading actions

Kind: global function

ParamTypeDescription
sagaGeneratorA long running saga
...argsanyArguments to be passed to the saga

wrapApiCall(call) ⇒ function

Wraps function with try/catch block to catch all the API errors and translate them to according exceptions.

Kind: global function
Returns: function - Wrapped API call function

ParamTypeDescription
callfunctionA function calling an API client and returning promise

ApiErrorToast()

A simple component that shows an error toast message

Kind: global function

ApiLoader()

A simple component that shows a loading indicator

Kind: global function