platzidev / redux-duck Goto Github PK
View Code? Open in Web Editor NEWHelper function to create Redux modules using the ducks-modular-redux proposal
License: MIT License
Helper function to create Redux modules using the ducks-modular-redux proposal
License: MIT License
myActionCreator(false);
will return:
{ type: 'MY_ACTION' }
without payload, cause it doesn't pass current check against undefined. FIX: #3
I was re-using an action type from another duck, and a weird bug stuck me:
// duck-a.js
import { SOME_ACTION_TYPE } from './duck-b'
// ... some other stuff ...
createReducer({
[SOME_ACTION_TYPE]: (state, action) => console.log('Reducer in A') || state;
});
// duck-b.js
const duck = createDuck('b');
// ... some other stuff ...
export const SOME_ACTION_TYPE = duck.defineType('SOME_ACTION_TYPE');
export const someAction = duck.createAction(SOME_ACTION_TYPE)
createReducer({
[SOME_ACTION_TYPE]: (state, action) => console.log('Reducer in B') || state
});
When I dispatch someAction
, the reducer in B is invoked, but not the reducer in A.
After spending hours I found that I was importing something from duck-a
to duck-b
as well, causing a circular dependency between duck-a
and duck-b
, which makes the imported SOME_ACTION_TYPE
becomes undefined
.
Although the circular dependency is entirely my fault, I think createReducer
can help me spot the circular dependency if createReducer
can throw error when undefined
is one of the object key.
There is currently no way to set FSA error and meta fields.
Maybe the actionType functions could have another optional argument with the information.
actionType(errorPayload, { error: true });
actionType(payload, { meta: { foo: 123 } });
This is of course a bit tricky when there is no payload but perhaps it is not too much of a problem
actionType(undefined, { error: true });
actionType(undefined, { meta: { foo: 123 } });
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.