Two styles of action in React / Redux?
I see the following two styles of action in Redux:
From the documentation :
export function createFoo(foo) {
return {
type: ActionTypes.CREATE_AUTHOR,,
foo
}
}
... and from another tutorial (PluralSight):
export function createFoo(foo) {
var newFoo = FooApi.saveFoo(foo);
Dispatcher.dispatch({
actionType: ActionTypes.CREATE_FOO,
foo: newFoo
});
}
The latter seems to have a lot of responsibility by instantiating the author and dispatching the event.
Why is there a difference in approach? Are these two separate idioms (perhaps middleware is expected to do the dispatch?).
source to share
The second example seems to be from the original Flux implementation, not Redux. Redux does not have a separate "dispatcher" and requires actions to have a field type
.
You may be interested to read my blog post The Tao of Redux, Part 1 - Implementation and Intent , which details the actual technical limitations that Redux requires and why, as well as the history and original intentions of its creation.
source to share