Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何使用可观察到重复次数的信号器?_.net_Asp.net Core_Redux_Redux Observable_Asp.net Core Signalr - Fatal编程技术网

.net 如何使用可观察到重复次数的信号器?

.net 如何使用可观察到重复次数的信号器?,.net,asp.net-core,redux,redux-observable,asp.net-core-signalr,.net,Asp.net Core,Redux,Redux Observable,Asp.net Core Signalr,我已经创建了Angular SPA应用程序。我在服务器端使用ASP.net内核,客户端状态由使用action reducer epics的redux observable处理。 其结构如下:我配置了store、根epics和根reducer,然后每个组件都有自己的epic、reducer和服务文件 我想在redux observable中容纳signalR,但无法将其正确集成。首先将您的中心事件作为observable。我适应了使用ASP.NET核心信号器 然后创建一个epic来启动hub(我使

我已经创建了Angular SPA应用程序。我在服务器端使用ASP.net内核,客户端状态由使用action reducer epics的redux observable处理。

其结构如下:我配置了store、根epics和根reducer,然后每个组件都有自己的epic、reducer和服务文件


我想在redux observable中容纳signalR,但无法将其正确集成。

首先将您的中心事件作为observable。我适应了使用ASP.NET核心信号器

然后创建一个epic来启动hub(我使用的是typescript),在启动时将该操作分派到某个地方

const startNotificationHubEpic: Epic<RootAction, RootAction, RootState, Services> = (action$, store, { notificationHub }) => {
    return action$.pipe(
       filter(isActionOf(startNotificationHub.request)),
       switchMap(action => 
            from(notificationHub.start()).pipe(
                   map(() => startNotificationHub.success()),
                   catchError(err => of(startNotificationHub.failure(err)))
        )));
}
const startNotificationHubEpic:Epic=(action$,store,{notificationHub})=>{
返回操作$.pipe(
过滤器(isActionOf(startNotificationHub.request)),
开关映射(操作=>
来自(notificationHub.start()).pipe(
映射(()=>startNotificationHub.success()),
catchError(err=>of(startNotificationHub.failure(err)))
)));
}
最后,使用startNotificationHub.success操作开始侦听集线器上您感兴趣的每个事件的rsjx事件流

const listenForMessageEpic: Epic<RootAction, RootAction, RootState, Services> = (action$, store, { notificationHub }) => {
    return action$.pipe(
        filter(isActionOf(startNotificationHub.success)),            
        switchMap(act => 
            notificationHub.on("Message", (messag: string) => ({message})).pipe(
                map(notif => onMessage(notif))
        )));
}
const listenformessagepic:Epic=(action$,store,{notificationHub})=>{
返回操作$.pipe(
筛选器(isActionOf(startNotificationHub.success)),
开关映射(act=>
notificationHub.on(“Message”,(messag:string)=>({Message})).pipe(
映射(notif=>onMessage(notif))
)));
}

onMessage操作反过来可以被另一个epic使用,或者在reducer中使用,以将通知数据传递给组件。

我制作了一个小型库,使用redux、rxjs和redux observable来处理实时信号器(.NET Core)事件:。它实现自动重新连接,无需任何额外设置。它非常灵活,因此您可以使用它来涵盖几乎任何场景,或者只需查看源代码即可构建您自己的解决方案。

一些代码和对您的问题的正确描述肯定会有所帮助。当然,我也会发布代码。此库似乎没有维护。没有文档,我在尝试构建时出错。似乎不值得使用。