Created
November 18, 2019 12:03
-
-
Save furkanacaryes/b1f8fb5ac1fc2df10420515b09c769f1 to your computer and use it in GitHub Desktop.
Element Oriented Approach
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
// Element Oriented Approach | |
// # Class Component | |
import * as questions from '../path/to/questions'; | |
import { createClassComponent } from '../path/to/factory'; | |
export const ClassComponent = addElementCreator([ | |
questions.enterComponentName, | |
questions.addStyle, | |
questions.connectStore, | |
questions.isHaveReducer | |
], () => createClassComponent); | |
// Centralized common method that all elements will call | |
// Process answers then start creation | |
const addElementCreator = ( | |
questions: any[], | |
creatorFunction: (options: any) => void | |
) => () => { | |
const answers = Inquirer.prompt(questions); | |
const options = prepareOptions(answers); | |
return () => creatorFunction(options); | |
}; | |
// Currently ElementType is being mapped twice | |
// for both questions and creatorFunctions. | |
// | |
// Element oriented approach keeps the questions and function | |
// in element's own definition and not even using map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment