Skip to content

Instantly share code, notes, and snippets.

@furkanacaryes
Created November 18, 2019 12:03
Show Gist options
  • Save furkanacaryes/b1f8fb5ac1fc2df10420515b09c769f1 to your computer and use it in GitHub Desktop.
Save furkanacaryes/b1f8fb5ac1fc2df10420515b09c769f1 to your computer and use it in GitHub Desktop.
Element Oriented Approach
// 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