Comments (6)
@xomyaq sure. You can type your maps at any level like this.
type firstReducer = () => {}
type secondReducer = () => {}
interface AllReducers {
root: firstReducer,
ui: secondReducer,
}
const initialState: Map<keyof AllReducers, AllReducers[keyof AllReducers]> = Map()
from redux-immutable.
You can use records in your redux app. The immutable api set method on Record collections works just fine. But the OP wanted to use records in order to use dot notation, and that only works for accessing property values, not setting them. Which means he'd still be forced to use the immutable api.
myRecord.b // 3
myRecord.b = 5 // throws Error
Also, you have to explicitly create each record instance with every single property value when initializing your state.
recordState: Record({ a: 1, b: 2 })
This works fine if you know for a fact that your initial state will always be initialized to a:1, b:2, and will never add another property. So this won't work:
recordState.set('c', '3') // throws no error since immutable ignores setting non-existent record properties
Thus you'd be forced to mix a top level record state with maps, and then will end up accessing them using the immutable api anyways.
Lastly, v4.0.0-rc.1 introduced breaking changes to records. They are no longer an immutable collection type, so sequence api methods like map, filter, forEach are no longer available.
https://github.com/facebook/immutable-js/releases/tag/v4.0.0-rc.1
Maps can be typed just like records. All that having records buys you is faster access and a guarantee of having specific properties always initialized. Personally, I use a map as the top level state, and then use records for my collections and all works perfectly. And I'm able to type them using typescript.
from redux-immutable.
Immutable records cannot be instantiated generically like map can. Have you tried to create a record, and then instantiate the initial state like so? I set the default values to undefined, but they can be anything you'd like.
const expectedState = Record({
bar: undefined,
foo: undefined
})
const initialState = expectedState({
bar: barReducer,
foo: fooReducer
})
// if the defaults are the same
const expectedState = Record({
bar: barReducer,
foo: fooReducer
})
const initialState = expectedState()
from redux-immutable.
from redux-immutable.
@JustFly1984 Can you please, explain what does he mean by
Records don't allow the set method after creation
https://facebook.github.io/immutable-js/docs/#/Record/set
Am I missing something ? I started to make records for my reducers's states, mostly to be able to type them with flow (since the Maps shape can't be typed).
Please, tell me it's ok with Immutable v4... I'm starting to think that Immutable is not a library you want in your redux app - bad news for me, I have a huge app running on Immutable Redux state.
from redux-immutable.
@JM-Mendez, hi! Sorry for unrelated question: can you please provide an example of typing Map on top level state? Thank you :)
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
- 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.