rx-event-source
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

RxEventSource

GitHub release (latest SemVer) All Contributors Gitpod Ready-to-Code codecov GitHub Workflow Status Snyk Vulnerabilities for GitHub Repo Semantic release npm bundle size GitHub

API Reference

Open in Gitpod

Background

Helper function to create an RxJS observable from EventSource.

Installation

NPM

npm install rx-event-source rxjs@7

or

yarn add rx-event-source rxjs@7

Usage

Basic usage

See available options.

import { eventSource$ } from 'rx-event-source';

const options = {
  // ...
};

eventSource$('/api/v1/sse', { withCredentials: false }, options).subscribe((data) => {
  console.log(data);
});

Handling streaming errors

The streaming error can be emitted as a message with specific data format and then handled manually by throwing an error.

import { eventSource$ } from 'rx-event-source';

const options = {
  // ...
};

function isError(data) {
  // ...
}

eventSource$('/api/v1/sse', { withCredentials: false }, options).pipe(
  map((data) => {
    if (isError(data)) {
      throw new Error(data.error);
    }
    return data;
  })
).subscribe((data) => {
  console.log(data);
});

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Katarina Anton

💻 🤔 🚧 ⚠️ 🔧 🚇

This project follows the all-contributors specification. Contributions of any kind welcome!

Readme

Keywords

Package Sidebar

Install

npm i rx-event-source

Weekly Downloads

0

Version

1.2.0

License

MIT

Unpacked Size

48.1 kB

Total Files

23

Last publish

Collaborators

  • kaciakmaciak