javascript - การใช้ RX กับตัวสร้าง yeoman
ฉันต้องการใช้ RXJS กับตัวสร้าง yeoman ของ typescript ตามเอกสาร inquirer ซึ่งเป็นเอนจินภายใต้ yeoman รองรับ RXJS
https://github.com/SBoudrias/Inquirer.js/#reactive-interface
I use the following
export default class myGenerator extends Generator {
...
async prompting() {
const prompts = new Subject<Generator.Question>();
await this.prompt(prompts);
prompts.next({
name: "appName",
message: "app name: ",
type: "input",
default: this.props!.appName,
validate(input: string) {
const appName = validateAppName(input);
return !appName[1] ? appName[0] : true;
},
});
prompts.next({
type: "list",
name: "tech",
message: "Which type",
default: "CLI",
choices: [{ name: "CLI" }, { name: "CloudApp" }],
});
prompts.complete();
}
ตอนนี้ในขณะที่กำลังรันมัน ฉันได้รับข้อผิดพลาด:
Error: You must provide a `name` parameter
at InputPrompt.throwParamError (/usr/local/lib/node_modules/yo/node_modules/inquirer/lib/prompts/base.js:73:11)
at new Prompt (/usr/local/lib/node_modules/yo/node_modules/inquirer/lib/prompts/base.js:33:12)
at new InputPrompt (/usr/local/lib/node_modules/yo/node_modules/inquirer/lib/prompts/input.js:11:1)
at PromptUI.fetchAnswer (/usr/local/lib/node_modules/yo/node_modules/inquirer/lib/ui/prompt.js:85:25)
at MergeMapSubscriber._tryNext (/usr/local/lib/node_modules/yo/node_modules/rxjs/internal/operators/mergeMap.js:69:27)
at MergeMapSubscriber._next (/usr/local/lib/node_modules/yo/node_modules/rxjs/internal/operators/mergeMap.js:59:18)
at MergeMapSubscriber.Subscriber.next (/usr/local/lib/node_modules/yo/node_modules/rxjs/internal/Subscriber.js:66:18)
at MergeMapSubscriber.notifyNext (/usr/local/lib/node_modules/yo/node_modules/rxjs/internal/operators/mergeMap.js:95:26)
at InnerSubscriber._next (/usr/local/lib/node_modules/yo/node_modules/rxjs/internal/InnerSubscriber.js:28:21)
at InnerSubscriber.Subscriber.next (/usr/local/lib/node_modules/yo/node_modules/rxjs/internal/Subscriber.js:66:18)
events.js:170
throw er; // Unhandled 'error' event
ฉันไม่แน่ใจว่าจะวาง name ไว้ที่ไหนเพราะคำสั่งทั้งหมดกำลังให้ property name, มีไอเดียไหม?
สิ่งที่ฉันต้องการคือการสร้าง คำถามง่าย ๆ สองข้อที่สามารถใช้งานกับ RXJS ฉันสามารถทำได้อย่างไร?