1.2.1 • Published 7 years ago

awral v1.2.1

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

AWRAL

Greenkeeper badge

Awesome Wrapper for Redux Action's Lifecycle

Swiss Army knife for async actions in Redux.

Why?

Assume you're using redux and redux-thunk.

README IN PROGRESS.

PLEASE, CHECK SOURCES!

When you work with async stuff you probably have next code in your container:

const mapDispatchToProps = dispatch => ({
	getUser (id) {
		dispatch(GET_USER(id))
	}
})

Where GET_USERS is a next async action:

export const GET_USER = id => async dispatch => {
	dispatch({type: 'GET_USER_PENDING'})
	const payload = await getUserFromServer(id)
	if (resultOK(payload)) {
		dispatch({type: 'GET_USER_SUCCESS', payload})
	} else {
		dispatch({type: 'GET_USER_FAIL', payload, error:true})
	}
	dispatch({type: 'GET_USER_FINALLY', payload})
}

With AWRAL you can just write:

const GET_USER = awral(getUserFromServer)('GET_USER')

How?

There is only one method: Awral.of(). of() allows you to extend/rewrite your "awrals":

import Awral from 'awral'
const checkResponseFromAPI = (result) => result.ok
const transformResultAfter = (result) => result.data
// const success = ({dispatch, payload}) => {}

const awralCheck = Awral.of({check: checkResponseFromAPI})
const awralCheckTransformBefore = awralCheck.of({})
const awral = Awral.of(check: checkResponseFromAPI)
1.2.1

7 years ago

1.2.0

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.0

7 years ago