standalone concat 不 return 一个 observable

standalone concat does not return an observable

我试图从可出租运算符的角度理解新的可观察对象 (rxjs)。为此,我有以下代码

        const messagesToDispatch = concat(
            of({ type: 'REGITERING_USER' }).delay(5000),
            of({ type: 'REGISTER_USER_COMPLETE', value })
        ).pipe();

        messagesToDispatch.subscribe(subValue => {
            console.log(subValue);
        });

现在,当我 运行 代码时,出现以下错误

messagesToDispatch.subscribe is not a function

然而,当我尝试以下操作时它有效

    concatMap(value => {
        const messagesToDispatch = Observable.concat(
            of({ type: 'REGITERING_USER' }).delay(5000),
            of({ type: 'REGISTER_USER_COMPLETE', value })
        );

        messagesToDispatch.subscribe(subValue => {
            console.log(subValue);
        });

注意我使用了 Observable.concat 而不是 concat。我不确定这里发生了什么。

如果你想 运行 你的代码没有错误,你需要在 RxJS6 中导入 concat 如下:

import {concat, of} from 'rxjs';

const messagesToDispatch = concat(
            of({ type: 'REGITERING_USER' }).pipe(delay(5000)),
            of({ type: 'REGISTER_USER_COMPLETE', value })
        );

还要注意如何使用 pipe