Comments (10)
I don't think it's a Redux issue. "Type" is an established convention, at least in Flux world, that's where most of our conventions come from. There need to be very good reasons to break these conventions, and more so after we shipped 1.0 and lots of code is already written using "type". I think that's something for redux-immutable to reconsider.
from redux-immutable.
I have rewritten the test to check if action has type
property and wether its value begins with "@@". These actions will be ignored, 85852fe.
@gaearon Is right in a sense that:
"Type" is an established convention, at least in Flux world, that's where most of our conventions come from.
This is also a convention defined in "flux-standard-action" spec. However, I have argued that "type" name as a convention does not make semantic sense.
"redux-immutable" implements the https://github.com/gajus/canonical-reducer-composition/ spec. Read the action object spec for more details. I will update the main "canonical-reducer-composition" description to include explanation why to use this "unconventional" spec over what has been established in flux land, but the short answer is: "canonical-reducer-composition" tries to be
- semantically correct
- follow conventions defined in the broader programming ecosystem
- more strict (e.g. FSA defines 3 allowable name variations of the "name" property: "type", "actionType" or "actionId" all of which are derived from the legacy standard and only the latter making the most sense.)
In the mean time, I am working on dev-tools that will work with both "redux" and "redux-immutable".
from redux-immutable.
@gajus This also breaks the logger middleware (it shows 'undefined' instead of the action type)
The community grow, middleware is the most pluggable way to extends Redux and is all about intercepting actions, if you don't get aligned with Redux convention things will just break,
At least make it configurable where default could be 'name',
(I guess we can just give the combineReducers
a 2nd hash options where you can configure the property name that indicates the action identifier.)
Thanks.
from redux-immutable.
@asaf Just an idea, but why not have a function at the top of the middleware chain that maps "type" to "name" in every action it receives? This way anyone can use whatever name they choose if they don't like "name" convention. I can write a quick middleware package for that.
The same middleware function could map other properties that do not meet the standard, such as "payload".
Does that sound like a good solution?
from redux-immutable.
A simplified version would look like this:
store = applyMiddleware(
mapper.fromCCAtoFSA,
/* all middleware that needs to be FSA compatible */
logger,
mapper.fromFSAtoCCA
)(createStore)(reducer, state);
Where the mapper is something along the lines of:
let fromCCAtoFSA,
fromFSAtoCCA;
fromCCAtoFSA = (store) => (next) => (action) => {
next({
type: action.name,
payload: action.data
});
};
fromFSAtoCCA = (store) => (next) => (action) => {
next({
name: action.type,
data: action.payload
});
};
export default {
fromCCAtoFSA,
fromFSAtoCCA
};
from redux-immutable.
@gajus 👍 I like this convention-conversion stuff.
from redux-immutable.
Ok. Will research certain aspects of the conversion (such as Error mapping) and release a package. Should be before the end of the day.
from redux-immutable.
The solution is to use middleware for converting between the two standards.
- https://github.com/gajus/redux-convention#middleware
- https://github.com/gajus/canonical-reducer-composition/blob/master/README.md#flux-standard-action
from redux-immutable.
@gajus This is still problematic, as @gaearon mentioned, "lots of code is already written using "type"", this also means reducers are being written in the community and expecting type, conversion to 'name' won't satisfy,
IMO, If you aim CCA out of the redux community you can diverge, but if you aim for Redux, you should be compatible with its standards otherwise community code will break.
from redux-immutable.
I use CRC as well as CCA in all the projects that I develop. I am sharing the CRC spec. I am sharing some libraries with the open source world and provide a method of bridging the different conventions. Sounds fair to me.
from redux-immutable.
Related Issues (20)
- React-router-redux selector documentation issue HOT 3
- Update from 3.0.9 to 3.0.10 causes flow-runtime errors HOT 1
- Link in README to combineReducers documentation is broken HOT 3
- Import state from redux-devtools not work HOT 4
- combineReducers not imported HOT 3
- Reducer is not a function (within state tree) HOT 1
- Add build option for es modules HOT 11
- State is undefined, can not get initial state HOT 2
- Trying to make it work with redux-auth
- Why can't I use Immutable.Record as initialState in rootReducer? HOT 6
- Changelog ? HOT 1
- please offer a browser built version HOT 6
- How to add non immutable store when combining reducers HOT 14
- bump dependancy to rc9 HOT 1
- Wrong return type of combineReducers HOT 10
- inputState.withMutations is not a function HOT 2
- Is this repo still maintained? HOT 2
- how to use redux hooks with redux-immutable? HOT 1
- Think I am seeing this too on IE11. This error HOT 1
- NPM release with the latest changes?
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 redux-immutable.