# redux-observable-signalr-core

> A library to handle realtime SignalR Core events using redux-observable and rxjs

Latest version **1.3.0** (published 2019-09-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install redux-observable-signalr-core
pnpm add redux-observable-signalr-core
yarn add redux-observable-signalr-core
bun add redux-observable-signalr-core
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2019-09-24 |
| First published | 2019-08-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 25.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Denys Kashkovskyi |
| Maintainers | mr-zoidberg |

## Links

- npm: https://www.npmjs.com/package/redux-observable-signalr-core
- Repository: https://github.com/Kashkovsky/redux-observable-signalr-core
- Homepage: https://github.com/Kashkovsky/redux-observable-signalr-core#readme
- Issues: https://github.com/Kashkovsky/redux-observable-signalr-core/issues
- npm.io page: https://npm.io/package/redux-observable-signalr-core

## Dependencies (2)

- [@aspnet/signalr](https://npm.io/package/@aspnet/signalr.md) ^1.1.4
- [typesafe-actions](https://npm.io/package/typesafe-actions.md) ^4.4.2

## Recent versions

- 1.3.0 (latest) — 2019-09-24
- 1.1.3 (alpha) — 2019-08-30
- 1.2.0 — 2019-08-30
- 1.1.2 — 2019-08-30
- 1.1.1 — 2019-08-30
- 1.1.0 — 2019-08-03
- 1.0.1 — 2019-08-02
- 1.0.0 — 2019-08-02

## README

# redux-observable-signalr-core
[![npm](https://img.shields.io/npm/dm/redux-observable-signalr-core.svg)]()
[![npm version](https://badge.fury.io/js/redux-observable-signalr-core.svg)](https://badge.fury.io/js/redux-observable-signalr-core)


A library to handle realtime SignalR (.NET Core) events using redux, rxjs and redux-observable.
Inspired by https://github.com/Odonno/ngrx-signalr-core

## Get started

### Install dependencies

```
npm install redux rxjs redux-obsevable @aspnet/signalr --save
npm install redux-observable-signalr-core --save
```

### Add signalR$ to your root Epic

```ts
import { signalR$ } from "redux-observable-signalr-core";

const epics = combineEpics(
	// other epics
	...signalR$
);
```

### Start with a single Hub

First, you will start the application by dispatching the creation of one Hub.

```ts
import { createSignalRHub } from "redux-observable-signalr-core/lib/actions";

// TODO : your hub definition
const hub = {
    hubName: 'hub name',
    url: 'https://localhost/path'
};

store.dispatch(createSignalRHub(hub));
```

Then you will create an Epic to start listening to events before starting the Hub.

```ts
import { signalrHubUnstarted, startSignalRHub } from "redux-observable-signalr-core/lib/actions";
import { mergeMapHubToAction } from "redux-observable-signalr-core/lib/operators";

const listenNotification$: Epic<Action, Action, IRootState> = action$ =>
	action$.pipe(
		filter(isActionOf(signalrHubUnstarted)),
		mergeMapHubToAction(({ hub }) => {

			const receiveNotification$ = hub
				.on<Notification>(method)
				.pipe(
					map(actions.notificationReceived)
				);

			const exististingNotifications$ = hub
				.on<Notification[]>(existing)
				.pipe(
					map(actions.getNotificationsSuccess)
				);

			return merge(receiveNotification$, exististingNotifications$, of(startSignalRHub(NotificationHub)));
		})
	);
```

You can also send events at anytime.

```ts
import { findHub } from "redux-observable-signalr-core/lib/signalRHub";
import { hubNotFound } from "redux-observable-signalr-core/lib/actions";

const sendNotification$: Epic<Action, Action, IRootState> = action$ =>
	action$.pipe(
		filter(isActionOf(actions.sendNotification)),
		mergeMap(action => {
			const hub = findHub(NotificationHub);
			if (!hub) {
				return of(hubNotFound(NotificationHub));
			}
			return hub
				.send(sendNotification, action.payload)
				.pipe(
					map(actions.sendNotificationSuccess),
					catchError((e) => of(actions.sendNotificationError))
				);
		})
	);
```

### Handling reconnection

Since .NET Core, client needs to handle the SignalR Hub reconnection by itself. `redux-observable-signalr-core` does it for you automatically, no additional setup required.

---
_Source: https://npm.io/package/redux-observable-signalr-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
