Skip to content

Commit

Permalink
Chore(inquirer): rxjs deprecation replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
SBoudrias committed Jun 26, 2024
1 parent 6b307b9 commit c300bb6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions packages/inquirer/examples/rx-observable-create.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Observable } from 'rxjs';
import inquirer from '../lib/inquirer.js';

const observe = Observable.create((obs) => {
obs.next({
const observe = new Observable((subscriber) => {
subscriber.next({
type: 'input',
name: 'first_name',
message: "What's your first name",
});

obs.next({
subscriber.next({
type: 'input',
name: 'last_name',
message: "What's your last name",
Expand All @@ -17,7 +17,7 @@ const observe = Observable.create((obs) => {
},
});

obs.next({
subscriber.next({
type: 'input',
name: 'phone',
message: "What's your phone number",
Expand All @@ -32,7 +32,7 @@ const observe = Observable.create((obs) => {
return 'Please enter a valid phone number';
},
});
obs.complete();
subscriber.complete();
});

inquirer.prompt(observe).then((answers) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/inquirer/lib/prompts/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import pc from 'picocolors';
import runAsync from 'run-async';
import { filter, flatMap, share, take, takeUntil } from 'rxjs';
import { filter, mergeMap, share, take, takeUntil } from 'rxjs';
import Choices from '../objects/choices.js';
import ScreenManager from '../utils/screen-manager.js';

Expand Down Expand Up @@ -91,7 +91,7 @@ export default class Prompt {
const validate = runAsync(this.opt.validate);
const asyncFilter = runAsync(this.opt.filter);
const validation = submit.pipe(
flatMap((value) => {
mergeMap((value) => {
this.startSpinner(value, this.opt.filteringText);
return asyncFilter(value, this.answers).then(
(filteredValue) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/inquirer/lib/ui/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const _ = {
};
import {
defer,
empty,
EMPTY,
from,
of,
concatMap,
Expand Down Expand Up @@ -134,11 +134,11 @@ export default class PromptUI extends Base {
question.askAnswered !== true &&
_.get(this.answers, question.name) !== undefined
) {
return empty();
return EMPTY;
}

if (question.when === false) {
return empty();
return EMPTY;
}

if (typeof question.when !== 'function') {
Expand Down
8 changes: 4 additions & 4 deletions packages/inquirer/test/specs/inquirer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,20 +420,20 @@ describe('inquirer.prompt', () => {
}));

it('takes an Observable as question', async () => {
const prompts = Observable.create((obs) => {
obs.next({
const prompts = new Observable((subscriber) => {
subscriber.next({
type: 'confirm',
name: 'q1',
message: 'message',
});
setTimeout(() => {
obs.next({
subscriber.next({
type: 'confirm',
name: 'q2',
message: 'message',
default: false,
});
obs.complete();
subscriber.complete();
promise.ui.rl.emit('line');
}, 30);
});
Expand Down

0 comments on commit c300bb6

Please sign in to comment.