Skip to content

Commit

Permalink
Merge pull request #31 from simpleweb/reducer-improvements
Browse files Browse the repository at this point in the history
Reducer improvements
  • Loading branch information
benjaminreid authored Mar 6, 2018
2 parents 97f65fb + b8a205c commit 3b315cb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
6 changes: 5 additions & 1 deletion generators/base/templates/App/Actions/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// @flow
export const APP_INSTALLED = '<%= name %>/APP_INSTALLED';

export const appInstalled = () => ({
export type AppInstalled = {
type: '<%= name %>/APP_INSTALLED',
};

export const appInstalled = (): AppInstalled => ({
type: APP_INSTALLED,
});
10 changes: 5 additions & 5 deletions generators/base/templates/App/Reducers/App.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// @flow
import { APP_INSTALLED } from '<%= name %>/App/Actions/App';
import type { AppInstalled } from '<%= name %>/App/Actions/App';

type State = {
installed: bool,
+installed: bool,
};

type Action = {
type: string,
};
type Action = AppInstalled;

const initialState = {
const initialState: State = {
installed: false,
};

Expand All @@ -22,6 +21,7 @@ const reducer = (state: State = initialState, action: Action): State => {
};

default:
(action: empty);
return state;
}
};
Expand Down
8 changes: 6 additions & 2 deletions generators/reducer/templates/actions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// @flow
export const <%= reducerConst %>_EXAMPLE = '<%= name %>/<%= reducerConst %>_EXAMPLE';
export const <%= reducerConst %>_EXAMPLE = "<%= name %>/<%= reducerConst %>_EXAMPLE";

export const <%= reducerSlug %>Example = () => ({
export type <%= reducer %>Example = {
type: "<%= name %>/<%= reducerConst %>_EXAMPLE",
};

export const <%= reducerSlug %>Example = ():<%= reducer %>Example => ({
type: <%= reducerConst %>_EXAMPLE,
});
18 changes: 13 additions & 5 deletions generators/reducer/templates/reducer.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
// @flow
import { <%= reducerConst %>_EXAMPLE } from '<%= name %>/App/Actions/<%= reducer %>';
import { <%= reducerConst %>_EXAMPLE } from "<%= name %>/App/Actions/<%= reducer %>";
import type { <%= reducer %>Example } from "<%= name %>/App/Actions/<%= reducer %>";

type State = {
+value: boolean,
};

type Action = {
type: string,
};
type Action = <%= reducer %>Example;

const initialState = {
const initialState: State = {
value: false,
};

const reducer = (state: State = initialState, action: Action): State => {
switch(action.type) {
case <%= reducerConst %>_EXAMPLE:
return {
...state,
value: true,
};

default:
(action: empty);
return state;
}
};
Expand Down

0 comments on commit 3b315cb

Please sign in to comment.