The idea to describe AC as pure functions is good but it has one disadvantage. It looks good only for sync stuff.
function addTodo() { return { type: TODO_ADDED, title: "rule the world" }; }
The main purpose of using AC is to isolate asynchronous stuff from other parts of architecture (like view layer and stores layer). And based on my experience on projects with server side (or another types of WebAPI that you can use) you will create a lot of async AC. So it would be better if the developer will be able to write async AC easy just like sync one.
Currently, I need to wrap all my async operations and use dispatch
function as a side effect.
function loadProjects(token) { return dispatch => { WebAPI.projects(token) .then(projects => dispatch({ type: PROJECTS_LOADED, data: projects })) }; }
Lets accept Promises and unwrap them to get Action instance
function loadProjects(token) { return WebAPI.projects(token) .then(projects => ({ type: PROJECTS_LOADED, data: projects })); }
I think it's a way to full consistency and purity.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4