Coder Social home page Coder Social logo

microsoft / rxrelayjs Goto Github PK

View Code? Open in Web Editor NEW
69.0 8.0 12.0 90 KB

Library that provides Relay types for rxjs. These are analogous to Subjects, but stateless and without the ability to call complete() or error().

License: Other

JavaScript 0.17% TypeScript 99.83%

rxrelayjs's Introduction

RxRelayJS

RxRelayJS is a TS/JS implementation of Jake Wharton's RxRelay. Relay types are analogous to Subject types, but without the ability to call complete() or error(). Therefore, they are stateless in the sense that they cannot enter a terminal state.

The most common usecase of Subject is to bridge between non-reactive APIs and reactive APIs. Typically, you do not want these bridges to enter any terminal state. The Relay types remove the possibility of this accidentally occuring.

Installation

Via NPM:

npm install rxrelayjs

Note: The rxjs package is listed as a required peerDependency.

Usage

RxRelayJS contains Relay types for each Subject type:

  1. Relay
  2. BehaviorRelay
  3. ReplayRelay

There is no AsyncRelay because the Relay type does not support the terminal state.

Relay

Emits all subsequent events to observers once they have subscribed.

const relay = new Relay();

relay.subscribe({
  next: (v) => console.log('observerA: ' + v)
});

relay.next(1);
relay.next(2);

relay.subscribe({
  next: (v) => console.log('observerB: ' + v)
});

relay.next(3);

Console output:

observerA: 1
observerA: 2
observerA: 3
observerB: 3

BehaviorRelay

Emits the most recent observed event and all subsequent events to observers once they have subscribed.

const relay = new BehaviorRelay(0);

relay.subscribe({
  next: (v) => console.log('observerA: ' + v)
});

relay.next(1);
relay.next(2);

relay.subscribe({
  next: (v) => console.log('observerB: ' + v)
});

relay.next(3);

Console output:

observerA: 0
observerA: 1
observerA: 2
observerB: 2
observerA: 3
observerB: 3

ReplayRelay

Emits all previously observed and subsequent events to observers once they have subscribed.

const relay = new ReplayRelay();

relay.subscribe({
  next: (v) => console.log('observerA: ' + v)
});

relay.next(1);
relay.next(2);

relay.subscribe({
  next: (v) => console.log('observerB: ' + v)
});

relay.next(3);

Console output:

observerA: 1
observerA: 2
observerB: 1
observerB: 2
observerA: 3
observerB: 3

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Commit messages should follow the conventional-changelog-standard. (the same used by RxJS)

e.g.

fix(imports): No longer automatically imports all of rxjs, respecting your bundle size strategy (e.g. if you use operator patching or `.pipe()`)

Closes #123

License

This project is licensed under the MIT License - see the LICENSE file for details.

rxrelayjs's People

Contributors

devholic avatar jayphelps avatar microsoftopensource avatar msftgits avatar ricsam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxrelayjs's Issues

Relay type does not conform to inherited Observable type

A relay should be assignable to an observable type. A common use case of a relay is to return it as an observable so downstream consumers can just treat it as an ordinary observable.

[ts]
Type 'Relay' is not assignable to type 'Observable'.
Property '_subscribe' is protected in type 'Relay' but public in type 'Observable'.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.