Comments (3)
I really like the idea about having action creators and other redux utils in Melting-Pot, what API do you propose we should have for this?
from melting-pot.
I propose the following
actionCreate = (prefix = '', action) => {
// e.g, prefix = 'user', action = 'profile'
const action = `${prefix}/action`;
const types = {
INIT: 'init/',
LOADING: 'loading/',
SUCCESS: 'success/',
ERROR: 'error/',
};
return Object.values(types).map(type => `${type}/action`.toUpperCase());
}
actionDispatcher = fetch => async dispatch {
const [init, loading, success, error] = actionCreate('user', 'get_profile');
try {
dispatch({ type: init }) // init is => INIT/USER/GET_PROFILE
dispatch({ type: loading }); // loading is=> LOADING/USER/GET_PROFILE
const payload = await fetch();
dispatch({ type: success, payload }) // success=> SUCCESS/USER/GET_PROFILE
return payload;
} catch (error) {
dispatch({ type: error}) // error is => ERROR/USER/GET_PROFILE
throw error;
}
}
Then use it something like this;
const myFooApiCall = async () => {
try {
const result = await fetch('http://some-api-call', {
method: '',
headers: {},
});
return result;
} catch (error) {
throw error;
}
}
// use it like this
dispatch(actionDispatcher(myFooApiCall))
What do you think? @sakhisheikh
So we end up with 2 utils,
- actionCreate
- actionDispatcher
from melting-pot.
@sakhisheikh are you going to be working on this issue?
from melting-pot.
Related Issues (20)
- [Docs] Remove nested folders of documentation from docs/hooks folder HOT 1
- [GIT] Add github issue templates HOT 3
- [Contributing] Update upstream path HOT 2
- [Feature] Add an npm ignore file, to reduce library download size
- [Feature] add new hook called useForm
- [Docs] Improve useToggle Documentation HOT 2
- [Docs] Improve useInterval Documentation
- [Feature] Add a new hook called useWillUnmount HOT 4
- [Docs] Enable CodeSandbox for documentation running on docz
- Add a pull request template HOT 1
- [Feature] useMouseMove HOT 2
- [Feature] Add an ISSUE_TEMPLATE for new feature
- [Feature] Add a new hook called useUpdate
- [Feature] We need to a template for PULL_REQUEST HOT 1
- Add eslint plugin for React hooks HOT 1
- Demo not working on iPad Safari HOT 2
- [Feature] Add a new hook called useToggle HOT 3
- [Enhancement] add dirty, pristine states to useFormField hook
- [Docs] Improve useScreenType documentation with example
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from melting-pot.