Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Execute default function to get default answer when -y flag is passed #185

Merged
merged 3 commits into from
Nov 15, 2019

Conversation

anku255
Copy link
Contributor

@anku255 anku255 commented Nov 14, 2019

Hi @kefranabg 👋

This PR fixes #180.

This is still a WIP. I need some help figuring this out.

Since author-website.js default function returns a promise. We need to change getDefaultAnswers as well. The problem is that we need to pass answersContext to every question and this is why we can't iterate over all the questions asynchronously anymore. I used for of loop to solve this issue but I feel there must be a better solution. Can you help me with it?

// utils.js

const getDefaultAnswers = async questions => {
  const answersContext = {}
  for (const question of questions) {
    answersContext[question.name] = await getDefaultAnswer(
      question,
      answersContext
    )
  }
  return answersContext
}

@kefranabg
Copy link
Owner

What do you think of this?

const getDefaultAnswers = async questions =>
  questions.reduce(async (answersContextProm, question) => {
    const answersContext = await answersContextProm

    return {
      ...answersContext,
      [question.name]: await getDefaultAnswer(question, answersContext)
    }
  }, Promise.resolve({}))

@anku255
Copy link
Contributor Author

anku255 commented Nov 15, 2019

const getDefaultAnswers = async questions =>
questions.reduce(async (answersContextProm, question) => {
const answersContext = await answersContextProm

return {
  ...answersContext,
  [question.name]: await getDefaultAnswer(question, answersContext)
}

}, Promise.resolve({}))

Ah! I had tried that but forgot to do add const answersContext = await answersContextProm and it wasn't working 🤣

I have updated the PR. Please take a look now 😊

@anku255 anku255 changed the title WIP: [Help Needed] (fixes #180) ✨Execute default function to get default answer when -y flag is passed (fixes #180) ✨Execute default function to get default answer when -y flag is passed Nov 15, 2019
@kefranabg kefranabg changed the title (fixes #180) ✨Execute default function to get default answer when -y flag is passed 🐛 Execute default function to get default answer when -y flag is passed Nov 15, 2019
Copy link
Owner

@kefranabg kefranabg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@kefranabg kefranabg merged commit 89cd82d into kefranabg:master Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Running readme-md-generator with -y flag breaks author website
2 participants