This file contains hidden or 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
import { postsActions } from '../actions/posts' | |
import { handleActions } from 'redux-actions' | |
const initialState = [] | |
const handlers = { | |
[postsActions.posts.set]: (state, action) => action.posts, | |
[postsActions.posts.append]: (state, action) => [...state, ...action.post] | |
} | |
export const postsReducer = handleActions(handlers, initialState) |
This file contains hidden or 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
import { createActions } from 'redux-actions' | |
export const postsActions = createActions({ | |
POSTS: { | |
SET: posts => ({ posts: posts }), | |
APPEND: post => ({ post: post }) | |
} | |
}) |
This file contains hidden or 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 postsReducer(state = [], action) { | |
switch (action.type) { | |
case "SET_POSTS": | |
return action.posts | |
case "APPEND_POSTS": | |
return [...state, ...action.post] | |
default: | |
return state | |
} | |
} |
This file contains hidden or 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 setPostsAction(posts) { | |
return { | |
type: 'SET_POSTS', posts: posts | |
} | |
} | |
export function appPostsAction(post) { | |
return { | |
type: 'APPEND_POSTS', post: post | |
} |
This file contains hidden or 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
function getURLParameter(name) { | |
return decodeURI( | |
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1] | |
); | |
} |