Skip to content

Instantly share code, notes, and snippets.

View mattcarbone's full-sized avatar
💭
🍕

Matt Carbone mattcarbone

💭
🍕
View GitHub Profile
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)
import { createActions } from 'redux-actions'
export const postsActions = createActions({
POSTS: {
SET: posts => ({ posts: posts }),
APPEND: post => ({ post: post })
}
})
export function postsReducer(state = [], action) {
switch (action.type) {
case "SET_POSTS":
return action.posts
case "APPEND_POSTS":
return [...state, ...action.post]
default:
return state
}
}
export function setPostsAction(posts) {
return {
type: 'SET_POSTS', posts: posts
}
}
export function appPostsAction(post) {
return {
type: 'APPEND_POSTS', post: post
}
function getURLParameter(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
);
}