Comments (5)
Hello rkusuma!
Yes, first, you select the state from the application state:
export function getCurrencies(state$: Observable<State>) {
return state$.select(state => state.currencies);
}
Then, you can compose selections of the properties within the state (ex. getting the currencies array)
export const getCurrencyEntities = compose(fromCurrencies.getCurrenciesEntities , getCurrencies);
When you select from the state within a component/directive/pipe/service, you have to use the selector from the root, not the selectors from the state you need:
//CORRECT
this.currencies = this._store.let(fromRoot.getCurrencyEntities);
//INCORRECT (will throw an exception)
this.currencies = this._store.let(fromCurrencies.getCurrencies));
I hope this answers your question!
from ngx-redux-app.
my reducer is quite deep... so it would harder to create selector function on each reducer.
Example State
{
a: {
b: {
c: {
xx: 10,
yy: 'Hi'
},
...
},
...
},
...
}
to get the value xx
from c
reducer i must create selector function in:
c
reducerb
reducera
reducer
and it's possible to c
reducer have many state.
from ngx-redux-app.
In this case, I would have a single reducer and a state (for a
), and handle all the selections and changes within the a.reducer.ts
and then expose them to the root reducer.
You can also compose multiple selectors in the root reducer as seen here between lines 146 and 152.
from ngx-redux-app.
yes, that's what i mean.
// app.reducer.ts
export interface State {
moduleA: fromModuleA.State,
moduleB: fromModuleB.State,
...
moduleD: fromModuleD.State
}
export const getModuleAState = (state) => state.moduleA;
export const getEntities = createSelector(getModuleAState, fromModuleA.getEntities);
// moduleA.reducer.ts
export interface State {
subModuleAA: fromSubModuleAA.State,
subModuleAA: fromSubModuleAA.State
}
export const getSubModuleAAState = (state) => state.subModuleAA;
export const getEntities = createSelector(getModuleAState, fromSubModuleAA.getEntities);
// sub-module-aa.reducer.ts
export interface State {
entities: Enttities[],
...
}
export const getEntities = (state) => state.entities;
as you can see, i need to create 3 getEntities
selector function to get entities
from SubModuleAA
reducer to App
reducer.
there is still module B, module C, and module D.
is it expected to create chain selector function?
from ngx-redux-app.
Well, this is the way to go. You can also use a chain selector to select everything from module A (using composition) if you wish instead of adding a separate selector for each of the substates.
from ngx-redux-app.
Related Issues (5)
- package.json is missing HOT 3
- Build errors HOT 2
- Build Issues HOT 1
- Issue with running the project HOT 1
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 ngx-redux-app.