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
export function reducer(state = initialState, action:articles.Actions):State { | |
switch(action.type){ | |
case ADD_ARTICLE: | |
return { | |
articles: [...state.articles,action.payload] | |
} | |
default: | |
return state; | |
} | |
} |
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
export interface Action { | |
type : string, | |
payload?: any | |
} | |
dispatch({type:’ADD_ARTICLE’,payload:{ | |
link:’github.com/philipszdavido’, | |
points:90 | |
} | |
}) | |
dispatch({type:’LOAD_LINKS’}) |
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
"styles": [ | |
"styles.css", | |
"../node_modules/bootstrap/dist/css/bootstrap.css", | |
"app/theme.css" | |
], | |
"scripts": [ | |
"../node_modules/jquery/dist/jquery.min.js", | |
"../node_modules/bootstrap/dist/js/bootstrap.js" | |
], |
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
//src/app/redux/models/article | |
export class Article { | |
id: number | |
link : string | |
title : string | |
points : number | |
constructor(id: number, title: string, link: string, points?: number) { | |
this.id = id | |
this.title = title; | |
this.link = link; |
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
//src/app/redux/actions/articles.ts | |
import { Action } from '@ngrx/store'; | |
import { Article } from '../models/article'; | |
export const ActionTypes = { | |
LOAD_ARTICLES:'Load Articles', | |
ADD_ARTICLE: 'Add Article', | |
INCREMENT_ARTICLE_POINT: 'Increment Article Point', | |
DECREMENT_ARTICLE_POINT: 'Decrememnt Article Point' | |
} |
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
//src/app/redux/reducer/articles.ts | |
import * as articles from '../actions/articles'; | |
import { Article } from '../models/article'; | |
export interface State { | |
articles : Array<Article>, | |
}; | |
export const initialState : State = { | |
articles : [], | |
}; |
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
export const getArticles = (state : State) => state.articles; |
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
//src/app/redux/reducer/index.ts | |
import { | |
combineReducers, | |
ActionReducer, | |
ActionReducerMap, | |
createSelector, | |
createFeatureSelector, | |
META_REDUCERS | |
} from '@ngrx/store'; | |
import * as fromArticle from '../reducer/articles'; |
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
//src/app/redux/reducer/index.ts | |
import * as fromArticle from '../reducer/articles'; | |
export interface State { | |
articles:fromArticle.State, | |
} |
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
//src/app/redux/reducer/index.ts | |
export const getArticleState = (state : State) => state.articles; | |
export const getArticles = createSelector(getArticleState,fromArticle.getArticles); |
OlderNewer