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

0.0.2 • Public • Published

NPM Tests

Svelte Store RxJS

Svelte Store RxJS provides Svelte Stores (readable, writable, derived) as RxJS Observables.

WARNING: This project is still experimental! Do not use in production!

Example:

import { derived, readable, Writable, writable } from 'svelte-store-rxjs';
import { filter } from 'rxjs/operators';
import { Observable } from 'rxjs';

// Writable
const a: Writable<number> = writable<number>(1);
a.subscribe(a => console.log('writable', a));
a.set(2);
a.update(state => state + 1);

// Readable
const b: Observable<number> = readable<number>(12);
b.subscribe(b => console.log('readable', b));

// Derived
const abSummed: Observable<number> = derived([a, b], ([a, b]) => {
  return a + b;
});
abSummed.subscribe(abSummed => console.log('summed', abSummed));

// All stores are true RxJS Observables, we can have RxJS fun with more than 100 RxJS operators :)
abSummed.pipe(
  // Filter out non-even numbers
  filter((num: number) => num % 2 === 0)
).subscribe(sum => console.log('RxJS pipe result', sum))

Readable, writable, derived are true RxJS Observables.

RxJS

  • writable() returns a Writable instance. Writable extends RxJS BehaviorSubject.
  • readable() and derived() return a RxJS Observable

References

Package Sidebar

Install

npm i svelte-store-rxjs

Weekly Downloads

3

Version

0.0.2

License

MIT

Unpacked Size

95.1 kB

Total Files

21

Last publish

Collaborators

  • spierala