Last active
September 6, 2016 14:27
-
-
Save donabrams/8d533b466d38f63ca6b7a78b80aae5a2 to your computer and use it in GitHub Desktop.
Javascript state machine example
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
import { ACTION_PUBLISH, ACTION_UNPUBLISH } from "./actions" | |
export const STATUS_DRAFT = "STATUS_DRAFT" | |
export const STATUS_PUBLISHED = "STATUS_PUBLISHED" | |
export const STATUS_UNPUBLISHED = "STATUS_UNPUBLISHED" | |
const initialState = { | |
status: STATUS_DRAFT | |
} | |
export default function postReducer(state = initialState, action) { | |
switch(action.type) { | |
case ACTION_PUBLISH: { | |
return { | |
status: STATUS_PUBLISHED | |
} | |
} | |
case ACTION_UNPUBLISH: { | |
return { | |
status: STATUS_UNPUBLISHED | |
} | |
} | |
default: { | |
return state; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment