Rx js-从其他文件导入UnaryFunction时,subscribe不是函数

问题描述 投票:0回答:1

我有以下问题。

给出两个文件,intents.tslogin.ts,其中intents.ts包含其他文件

export const loginUiEventsHandler =
    publish((uiEvents: Observable<UiEvents>) =>
        merge(
            uiEvents.pipe(filter(e => e.type === 'EMAIL_LOGIN_CHANGE'), flatMap((e: EmailLoginChange) => validateEmailLogin(e.emailLogin))),
            uiEvents.pipe(filter(e => e.type === 'PASSWORD_CHANGE'), flatMap((e: PasswordChange) => validatePassword(e.password))),
            uiEvents.pipe(filter(e => e.type === 'LOGIN_CLICK'), flatMap((e: LoginClick) => login(e.emailLogin, e.password)))
        )
    )

[login.js包含其他内容

events
    .pipe(loginUiEventsHandler)
    .subscribe(e => console.log(e))

[当我尝试使用loginUiEventsHandler将功能intents.tslogin.ts导入到import { loginUiEventsHandler } from './intents';时,出现错误

TypeError: selector(...).subscribe is not a function

但是,当我只复制粘贴相同的函数到login.ts时,一切似乎都正常。

我做错了什么?如何跨文件重用rxjs UnaryFunction。

如果这个问题显而易见,请原谅,我只是刚开始使用打字稿。

javascript typescript rxjs rxjs6
1个回答
0
投票
export const loginUiEventsHandler = () => // This is needed publish((uiEvents: Observable<UiEvents>) => merge( uiEvents.pipe(filter(e => e.type === 'EMAIL_LOGIN_CHANGE'), flatMap((e: EmailLoginChange) => validateEmailLogin(e.emailLogin))), uiEvents.pipe(filter(e => e.type === 'PASSWORD_CHANGE'), flatMap((e: PasswordChange) => validatePassword(e.password))), uiEvents.pipe(filter(e => e.type === 'LOGIN_CLICK'), flatMap((e: LoginClick) => login(e.emailLogin, e.password))) ) )

0
投票
© www.soinside.com 2019 - 2024. All rights reserved.