Populate NGRX store on load with dummy data only in development mode (eg: ng serve)

98 views Asked by At

I want to populate NGRX store with initial dummy data when ng serve, so my devs who are working on the app don't have to comment/uncomment out mock data manually while they are developing.

I have a JSON file with mock data, I just want to know what the best practice is to populate the store during ng serve.

1

There are 1 answers

1
Jamil On
  1. Create a Reducer event (on(...)) that get the containt of json file and set it in the state.
  2. Link the Reducer event to an Action.
  3. Dispatch the Reducer in the app.component.ts ngOnInit after a suitable condition (like to check the environment or so).

Note: if the json file is too big so try to show a message to notify the user to wait.