rxjs-addons
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

Rx add-ons

NPM version

Installation

$ npm i rxjs-addons -S

Example usage

AttributesProxySubject

import { AttributesProxySubject } from "rxjs-addons";
const subject = new AttributesProxySubject({
  a: 1,
  b: 2,
}, {
  schema: {
    a: {
      getter: true,
      setter: true
    },
    b: {
      subject,
    },
  },
});
 
console.log(subject.a) // 1
console.log(subject.b) // undefined
 
subject.b$.subscribe((value) => console.log("b:", value));
 
/*
  b: 2
 */
 

ErrorSubject

import { ErrorSubject } from "rxjs-addons";
const subject = new ErrorSubject();
 
subject.subscribe((err) => console.error(err));
 
// regular catch
try {
  throw new Error("Error");
} catch (err) {
  subject.error(err); // or errorSubject.next(err); 
}
 
// wrapping promise or async function 
subject.wrapAsync(async () => {
  throw new Error("Error");
});
subject.wrapAsync(Promise.reject(new Error("Error")));
 
// wrapping promise or async function and return promise
subject
  .wrapTAsync<string>(async () => {
    ... // 
    return "value";
  })
  .then((value) => console.log(value));

UniqueBehaviorSubject

import { UniqueBehaviorSubject } from "rxjs-addons";
const subject = new UniqueBehaviorSubject(1); // with default value
 
console.log(subject.value); // 1
 
subject.next(2);
subject.next(2);
subject.next(2);
subject.next(3);
subject.next(3);
 
subject.subscribe((value) => console.log("value:", value));
 
/*
  value: 1
  value: 2
  value: 3
 */
 

Testing

$ npm test

License

The MIT License

Readme

Keywords

none

Package Sidebar

Install

npm i rxjs-addons

Weekly Downloads

10

Version

0.0.4

License

MIT

Unpacked Size

16.8 kB

Total Files

41

Last publish

Collaborators

  • staszek