State: Event
State is required for Earthquake Event geo-json data. This state will require loading actions, a state interface describing the structure of the state, a reducer to handle the loading actions, effects to invoke retrieval of said state data, and selectors to retrieve the data from state.
Actions should be created with the NgRx createAction
utility function.
Effects should be created with the NgRx createEffect
utility function.
Selectors should be created with the NgRx createSelector
utility function.
Reducers should be created with the NgRx createReducer
utility function.
- Note: For AOT compilation purposes, the created reducer must be wrapped in a static function (see below)
Actions:
-
loadEvents
(initiator)- Parameters:
- criteria:
EventFilter
- criteria:
- Parameters:
-
loadEventsSuccess
(result)- Parameters:
- events:
EventGeo
- events:
- Parameters:
-
loadEventsFailure
(result)- Parameters:
- error: any
- Parameters:
State Interface:
- Should be mapped in app state interface in state/index.ts
- Name:
IEventState
- Properties:
- events:
EventGeo
- Optional
- isLoading: boolean
- Default: false
- loadedAt: Date
- Optional
- lastError: any
- Optional
- events:
Reducer:
- Should handle all actions defined above
- Should be mapped into reducer map in state/index.ts
- Must be wrapped in an AOT compatible function named for the state
export function eventReducer(state = initialState, action: Action): IEventState {
return reducer(state, action); // The function reducer here is created with the createReducer utility
}
Effects:
-
loadEvents$
: Should load EventGeo data usingEventService
:- On Success: dispatch
loadEventsSuccess
with events data - On Error: dispatch
loadEventsFailure
with error
- On Success: dispatch
- Should be registered with
EffectsModule
in app.module.ts
Selectors:
- allFeatures: Retrieve all
Feature
s fromEventGeo
data in state - eventsIsLoading: Retrieve loading flag
- eventsLoadedAt: Retrieve loaded at timestamp
- eventsLoadedAtFormatted: Retrieve loaded at timestamp as formatted text
- eventsLoadError: Retrieve last load error
Edited by Jon Rista