-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17ee25e
commit fabe8b9
Showing
7 changed files
with
154 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { createAction, createFeatureSelector, createReducer, createSelector, on, props } from '@ngrx/store'; | ||
|
||
export const DB_KEY = 'DATA_BASE'; | ||
|
||
export interface DBState { | ||
count: number; | ||
updatedAt?: number; | ||
} | ||
|
||
/** ACTIONS */ | ||
export const add = createAction('[DATA_BASE] add'); | ||
export const remove = createAction('[DATA_BASE] remove'); | ||
export const update = createAction('[DATA_BASE] update'); | ||
|
||
export const initialState: DBState = { | ||
count: 0 | ||
}; | ||
|
||
/** REDUCERS */ | ||
export const dbReducer = createReducer( | ||
initialState, | ||
on(add, state => ({ | ||
...state, | ||
count: state.count + 1 | ||
})), | ||
on(remove, state => ({ | ||
...state, | ||
count: state.count - 1 | ||
})), | ||
on(update, state => ({ | ||
...state, | ||
count: 0 | ||
})) | ||
); | ||
/** SELECTORS */ | ||
export const featureSelector | ||
= createFeatureSelector<DBState>(DB_KEY); | ||
export const countSelector = createSelector( | ||
featureSelector, | ||
state => state.count | ||
); | ||
export const updatedAtSelector = createSelector( | ||
featureSelector, | ||
state => state.updatedAt | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { | ||
ActionReducer, | ||
ActionReducerMap, | ||
createFeatureSelector, | ||
createSelector, | ||
MetaReducer | ||
} from '@ngrx/store'; | ||
import { environment } from '../../environments/environment'; | ||
|
||
export interface State { | ||
|
||
} | ||
|
||
export const reducers: ActionReducerMap<State> = { | ||
|
||
}; | ||
|
||
|
||
export const metaReducers: MetaReducer<State>[] = !environment.production ? [] : []; |