Comments (3)
// Interface
export interface CircuitListState extends EntityState<ICircuit> {
loaded: boolean;
loading: boolean;
}
// Create adapter
export const CircuitAdapter: EntityAdapter<ICircuit> = createEntityAdapter<ICircuit>({
sortComparer: false
});
// Init
export const initialStateEntity: CircuitListState = CircuitAdapter.getInitialState({
loaded: false,
loading: false
});
@Injectable()
@Store<CircuitListState>(initialStateEntity)
export class CircuitReducerV2 {
constructor(
private circuitsService: CircuitsService
) {}
@Action(CircuitsModule.SuccessLoadCircuit)
SuccessLoadCircuit(
state: CircuitListState,
action: CircuitsModule.SuccessLoadCircuit
) {
return {
...CircuitAdapter.addMany(action.payload, state),
loading: false,
loaded: true
};
}
@Action(CircuitsModule.LoadCircuit)
LoadCircuit(
state: CircuitListState,
action: CircuitsModule.LoadCircuit
) {
return {
...CircuitAdapter.removeAll(state),
loading: true
};
}
@Action(CircuitsModule.AddManyCircuit)
AddManyCircuit(
state: CircuitListState,
action: CircuitsModule.AddManyCircuit
) {
return {
...CircuitAdapter.addMany(action.payload, state)
};
}
@Action(CircuitsModule.RemoveOneCircuit)
RemoveOneCircuit(
state: CircuitListState,
action: CircuitsModule.RemoveOneCircuit
) {
return CircuitAdapter.removeOne(action.payload, state);
}
@Action(CircuitsModule.PatchCircuit)
PatchCircuit(
state: CircuitListState,
action: CircuitsModule.PatchCircuit
) {
return CircuitAdapter.updateOne({id: action.payload.id, changes: action.payload}, state);
}
@Effect(FiltersModule.ChangeUserFilters)
RequestCircuits(
state: CircuitListState,
action: FiltersModule.ChangeUserFilters
) {
const ids = filterUserConfig(action.payload);
const httpParams = { location_id: ids.join(','), status: 'to_plan' };
return this.circuitsService.getCircuits(httpParams)
.pipe(
map(data => new CircuitsModule.SuccessLoadCircuit(data)),
catchError(err => of(new ErrorModule.ErrorHandle(err)))
);
}
@Effect(TechnicianSelectedModule.AddNewSingleProgrammation)
DeleteCircuit(
state: CircuitListState,
action: TechnicianSelectedModule.AddNewSingleProgrammation
) {
return new CircuitsModule.RemoveOneCircuit(action.payload.circuit.id);
}
}
from ngrx-actions.
@abalad it work like before, juste pass the getInitialState of your adapter to the Store Decorator
from ngrx-actions.
@fausfore Thanks now I understood how to do, with this example even answered my other issue
#41
from ngrx-actions.
Related Issues (20)
- Action options HOT 1
- Store DI
- Return Store initial state to be used in the tests
- Can it be used with redux? HOT 1
- New @Effect decorator HOT 3
- @Action - samples in the README and articles are incorrect?
- NgrxActionsModule.forFeature - not working?
- @Dispatch
- Question: Unit testing with the @Select decorator
- RxJs 6 - Property 'pipe' does not exist in type 'Actions<Action>' HOT 1
- feat: support angular v6
- Question: any ETA for a ng6 compatible version? HOT 5
- Cannot find module 'ngrx-actions' HOT 8
- NgrxActionsModule nested reducers
- Publish 4.0.1 to NPM?
- Unexpected state mutation in reducers
- @Effect() decorator does not work HOT 1
- NGRX 7.x Upgrade HOT 2
- PLEASE DELETE. CREATED BY MISTAKE :D
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 ngrx-actions.