Skip to content

Commit 225818b

Browse files
committed
fix issue where local vars didnt update
1 parent 2ad8dc0 commit 225818b

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

example.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ const { prompt } = require('./lib');
3131
message: 'Can you confirm?'
3232
},
3333
{
34-
type: 'list',
35-
name: 'keywords',
36-
message: 'Enter keywords'
37-
},
38-
{
39-
type: 'toggle',
34+
type: prev => prev && 'toggle',
4035
name: 'confirmtoggle',
41-
message: 'Can you confirm?',
36+
message: 'Can you confirm again?',
4237
active: 'yes',
4338
inactive: 'no'
4439
},
40+
{
41+
type: 'list',
42+
name: 'keywords',
43+
message: 'Enter keywords'
44+
},
4545
{
4646
type: 'select',
4747
name: 'color',

lib/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const noop = () => {};
1313
async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
1414
const answers = {};
1515
questions = [].concat(questions);
16-
let answer, question, quit, name, type, key;
16+
let answer, question, quit, name, type;
1717
let MAP = prompt._map || {};
1818

1919
for (question of questions) {
@@ -30,12 +30,16 @@ async function prompt(questions=[], { onSubmit=noop, onCancel=noop }={}) {
3030
}
3131

3232
// if property is a function, invoke it unless it's ignored
33-
for (key in question) {
33+
for (let key in question) {
3434
if (ignore.includes(key)) continue;
3535
let value = question[key];
3636
question[key] = typeof value === 'function' ? await value(answer, { ...answers }, question) : value;
3737
}
3838

39+
// update vars in case they changed
40+
({ name, type } = question);
41+
42+
3943
// skip if type is a falsy value
4044
if (!type) continue;
4145

0 commit comments

Comments
 (0)