-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f657fa8
commit fecf8dd
Showing
4 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
var Generator = require('yeoman-generator'); | ||
var path = require('path'); | ||
|
||
module.exports = class extends Generator { | ||
constructor(args, opts) { | ||
super(args, opts); | ||
|
||
// name of the app based on the directory name generated by React Native | ||
this.name = process.cwd().split(path.sep).pop(); | ||
|
||
this.argument('reducer', { type: String, required: true }); | ||
} | ||
|
||
writing() { | ||
var reducer = this.options.reducer; | ||
var reducerConst = reducer.toUpperCase(); | ||
var reducerSlug = reducer.toLowerCase(); | ||
|
||
// create entry points for Android and iOS | ||
this.fs.copyTpl( | ||
this.templatePath('reducer.js'), | ||
this.destinationPath(`App/Reducers/${reducer}.js`), | ||
{ | ||
name: this.name, | ||
reducer: reducer, | ||
reducerConst: reducerConst, | ||
reducerSlug: reducerSlug, | ||
} | ||
); | ||
|
||
this.fs.copyTpl( | ||
this.templatePath('actions.js'), | ||
this.destinationPath(`App/Actions/${reducer}.js`), | ||
{ | ||
name: this.name, | ||
reducer: reducer, | ||
reducerConst: reducerConst, | ||
reducerSlug: reducerSlug, | ||
} | ||
); | ||
} | ||
|
||
end() { | ||
var reducer = this.options.reducer; | ||
var reducerConst = reducer.toUpperCase(); | ||
var reducerSlug = reducer.toLowerCase(); | ||
|
||
this.log('Please make sure to add this to your root reducer.'); | ||
this.log('App/Reducers/index.js'); | ||
this.log(` | ||
import ${reducer} from '${this.name}/App/Reducers/${reducer}'; | ||
const reducers = combineReducers({ | ||
// ...other reducers | ||
${reducerSlug}: ${reducer}, | ||
}); | ||
`); | ||
} | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// @flow | ||
export const <%= reducerConst %>_EXAMPLE = '<%= name %>/<%= reducerConst %>_EXAMPLE'; | ||
|
||
export const <%= reducerSlug %>Example = () => ({ | ||
type: <%= reducerConst %>_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// @flow | ||
import { <%= reducerConst %>_EXAMPLE } from '<%= name %>/App/Actions/<%= reducer %>'; | ||
|
||
type State = { | ||
}; | ||
|
||
type Action = { | ||
type: string, | ||
}; | ||
|
||
const initialState = { | ||
}; | ||
|
||
const reducer = (state: State = initialState, action: Action): State => { | ||
switch(action.type) { | ||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export default reducer; |