A quick example of ngrx integrated with Ionic Framework 3.
Install packages as usual:
npm install
The packages that are new to this repo are:
npm i --save reselect ngrx-store-ionic-storage @ngrx/core @ngrx/effects @ngrx/store @ngrx/store-devtools
ionic cordova plugin add cordova-sqlite-storage --save
The default home page is set to the Settings page. Run as usual, change the example settings, and reload the browser - your changes will persist between refreshes.
ionic serve
For an introduction to NGRX, see this gist.
File structure for a "settings" store:
mkdir -p src/stores/settings
touch src/stores/settings/settings.actions.ts
touch src/stores/settings/settings.model.ts
touch src/stores/settings/settings.reducer.ts
touch src/stores/settings/settings.effects.ts
To integrate a new store:
- Create new store directory and files
- Minimum: action and reducer files
- Modify src/app/app.module.ts
- Import store effects, add to
EffectsModule.forRoot([])
- Modify the
initialState{}
StoreModule if needed
- Import store effects, add to
- Modify src/stores/index.ts
- Import store reducer and actions
- Add store.State to
State
interface - Add store.reducer to
reducers: ActionReducerMap
- Add store key (as defined in
reducers
) tostorageSyncReducer
- Add Store state accessors as needed
Ionic Framework does not include a testing framework by default.
If you decide to set tests up, see the following testing documents: