packages/brookjs-cli/templates/project/new/dir-state-index.js.ejs
---
to: "<%= name %>/<%= dir %>/state/index.<%= locals.typescript ? 'ts' : 'js' %>"
---
<% reducerCreator = locals.typescript ? 'createReducer' : 'handleActions' -%>
import { <%= reducerCreator %><%= locals.typescript ? ', getType' : '' %> } from '<%= locals.typescript ? 'typesafe-actions' : 'redux-actions' %>';
import { incrementClick, decrementClick } from '../actions';
<% if(locals.typescript) { %>
export type State = {
count: number;
};
<% } %>
const initialState = {
count: 0,
};
export const reducer = <%= reducerCreator %><% if(locals.typescript) { %><State><% } %>(<% if(locals.typescript) { %>initialState, {
[getType(incrementClick)]: state => ({ ...state, count: state.count + 1 }),
[getType(decrementClick)]: state => ({ ...state, count: state.count - 1 }),
})<% } else { %>
{
[incrementClick]: state => ({ ...state, count: state.count + 1 }),
[decrementClick]: state => ({ ...state, count: state.count - 1 }),
},
initialState,
)<% } %>;
export const mapStateToProps = state => ({
count: state.count,
});