File tree Expand file tree Collapse file tree 8 files changed +39
-15
lines changed
Expand file tree Collapse file tree 8 files changed +39
-15
lines changed Original file line number Diff line number Diff line change 1+ - v0.2.1 Export enum for action types
12- v0.2.0 Add ` Add Redux Reducer ` Action
23- v0.1.0 Add ` Add React Component ` Action
Original file line number Diff line number Diff line change 11<idea-plugin >
22 <id >com.faebeee.reactcomponentcreator</id >
33 <name >React Component Creator</name >
4- <version >0.3.0 </version >
4+ <version >0.3.1 </version >
55 <
vendor email =
" [email protected] " url =
" http://fabs.io" >Fabio Gianini</
vendor >
66
77 <!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
2424
2525 <change-notes >
2626 <![CDATA[
27- <ul>
28- <li>v0.2.0 Add <code>Add Redux Reducer</code> Action</li>
27+ <ul>
28+ <li>v0.3.1 Export enum for action types</li>
29+ <li>v0.3.0 Add <code>Add Redux Reducer</code> Action</li>
30+ <li>v0.2.0 Update UI & improve code</li>
2931 <li>v0.1.0 Add <code>Add React Component</code> Action</li>
3032 </ul>
3133 ]]>
Original file line number Diff line number Diff line change 1- export const { { mutationType } } = '{ { moduleName } }/{ { mutationType } }';
1+ export enum { { actionTypesEnumName } } {
2+ {{ mutationType } } = '{ { moduleName } }/{ { mutationType } }',
3+ }
Original file line number Diff line number Diff line change 11import { Dispatch } from 'redux';
2- import { {{ mutationType } } } from './action-types';
2+ import { {{ actionTypesEnumName } } } from './action-types';
33import { {{ actionTypeName } } } from './types';
44
5- export const { { actionFunctionName } } = () => async (dispatch: Dispatch<{ { actionTypeName } }>) => {
5+ export const { { actionFunctionName } } = () => async (dispatch: Dispatch<{ { actionTypesEnumName } }. { { actionTypeName } }>) => {
66 dispatch({ type: {{ mutationType } } , data });
77};
Original file line number Diff line number Diff line change 11import { {{ moduleNamePascalCase } }Actions, { { stateName } } } from './types';
2- import { {{ mutationType } } } from './action-types';
2+ import { {{ actionTypesEnumName } } } from './action-types';
33
44export const initialState: { { stateName } } = {
55} ;
66
7- export default function { { moduleName } }Reducer(state = initialState, action: { { moduleNamePascalCase } }Actions): { { stateName } } {
7+ export default function { { moduleNamePascalCase } }Reducer(state = initialState, action: { { moduleNamePascalCase } }Actions): { { stateName } } {
88 switch (action.type) {
9- case {{ mutationType } }:
9+ case {{ actionTypesEnumName } }. { { mutationType } }:
1010 return {
1111 ...state,
1212 } ;
Original file line number Diff line number Diff line change 11import { Action } from 'redux';
2- import { {{ mutationType } } } from './action-types';
2+ import { {{ actionTypesEnumName } } } from './action-types';
33
44export interface { { stateName } } {
55}
66
7- export type { { actionTypeName } } = Action<{ { mutationType } }> & {
7+ export type { { actionTypeName } } = Action< { { actionTypesEnumName } }. { { mutationType } }> & {
88}
99
1010export type { { moduleNamePascalCase } }Actions = { { actionTypeName } };
Original file line number Diff line number Diff line change @@ -60,13 +60,15 @@ public ArrayList<String> getFiles() {
6060 public Map <String , Object > getTemplateVars () {
6161 Map <String , Object > templateModel = new HashMap <>();
6262 String actionFunctionName = actionNameTextField .getText ();
63+ String moduleName = moduleNameTextField .getText ();
6364
6465 templateModel .put ("actionFunctionName" , actionFunctionName );
65- templateModel .put ("moduleName" , StringFormatter . toCamelCase ( moduleNameTextField . getText ()) );
66- templateModel .put ("moduleNamePascalCase" , StringFormatter .toCamelCase (moduleNameTextField . getText () ));
67- templateModel .put ("stateName" , StringFormatter .toCamelCase (moduleNameTextField . getText () ) + "State" );
66+ templateModel .put ("moduleName" , moduleName );
67+ templateModel .put ("moduleNamePascalCase" , StringFormatter .toCamelCase (moduleName ));
68+ templateModel .put ("stateName" , StringFormatter .toCamelCase (moduleName ) + "State" );
6869 templateModel .put ("mutationType" , mutationNametextField .getText ());
69- templateModel .put ("actionTypeName" , StringFormatter .capitalizeFirst (actionFunctionName )+"Action" );
70+ templateModel .put ("actionTypeName" , StringFormatter .capitalizeFirst (actionFunctionName ) + "Action" );
71+ templateModel .put ("actionTypesEnumName" , StringFormatter .toDashCase (moduleName ).toUpperCase () + "_ACTIONS" );
7072
7173 return templateModel ;
7274 }
Original file line number Diff line number Diff line change @@ -23,6 +23,23 @@ public static String toCamelCase(String input) {
2323 return sb .toString ();
2424 }
2525
26+ public static String toDashCase (String input ) {
27+ StringBuffer sb = new StringBuffer ();
28+ int c = 0 ;
29+ for (String s : input .split ("-" )) {
30+ if (c != 0 ) {
31+ sb .append ("_" );
32+ }
33+
34+ sb .append (Character .toLowerCase (s .charAt (0 )));
35+ if (s .length () > 1 ) {
36+ sb .append (s .substring (1 , s .length ()).toLowerCase ());
37+ }
38+ c ++;
39+ }
40+ return sb .toString ();
41+ }
42+
2643 public static String capitalizeFirst (String input ) {
2744 return input .substring (0 , 1 ).toUpperCase () + input .substring (1 );
2845 }
You can’t perform that action at this time.
0 commit comments