taekimjr / redux-ask Goto Github PK
View Code? Open in Web Editor NEWRemove boilerplate around requests... just ask!
License: MIT License
Remove boilerplate around requests... just ask!
License: MIT License
We can create live examples using Code Sandbox! https://codesandbox.io/s/new
Let's move all our examples to here!
A lot of times users will want to make multiple requests in a row, perhaps using the response of one request as an input into another. We can do this with Redux Ask! But we need to show examples of this to make users aware.
// getUser & getUserFriends are pre-created requests (using createRequest)
handleSubmit = () => {
const { userId, getUser, getUserFriends } = this.props;
getUser(userId)
.then(user => {
return getUserFriends(user.id);
})
.then(friends => {
// More chains possible
}) ;
}
Redux Ask is built out to allow receiving and normalizing entities easy! We should create an example to show users how to do this and how this should be done (in the onSuccess
handler).
It's important this is done within the onSuccess
handler so the success flag does not get set until receiving / normalization is complete.
createRequest(id => ({
url: `/users/${id}`,
method: 'GET',
onSuccess: user => dispatch => {
const normalized = normalizeUser(user);
dispatch(receiveEntities(normalized));
},
}));
We should provide a helper selector to determine the status of multiple selectors. This will make it easy to gather a collection of different data.
I was thinking something along the lines of...
const mapStateToProps = state => {
return {
allSuccessful: allSuccessfulSelector(['REQUEST_1', 'REQUEST_2', 'REQUEST_3'])(state),
anySuccessful: anySuccessfulSelector(['REQUEST_1', 'REQUEST_2', 'REQUEST_3'])(state),
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.