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

0.5.3 • Public • Published

npm ci codacy codecov Vercel

A tiny component that observes observables for you

Example app available @ Vercel

Usage

Install:

npm install svelte-rxjs-observer

Examples

Simple

<script lang="ts">
  import { Subject } from 'rxjs';
  import { Observer } from 'svelte-rxjs-observer';

  let subject = new Subject<number>();
</script>

<Observer {subject} let:next>
  {next}
  <svelte:fragment slot="pending">loading...</svelte:fragment>
</Observer>

Typed error and completion states

<script lang="ts">
  import { Subject } from 'rxjs';
  import { Observer } from 'svelte-rxjs-observer';

  let subject = new Subject<number>();
  let errorType: TypeError; // Optinal typehint for the error
</script>

<Observer {subject} let:next {errorType}>
  {stringify({ next })}
  <svelte:fragment slot="pending">
    {stringify({ slot: 'pending' })}
  </svelte:fragment>
  <svelte:fragment slot="error" let:error let:last>
    {stringify({ slot: 'error', error: { message: error.message }, last })}
  </svelte:fragment>
  <svelte:fragment slot="completed" let:last>
    {stringify({ slot: 'completed', last })}
  </svelte:fragment>
</Observer>

Package Sidebar

Install

npm i svelte-rxjs-observer

Weekly Downloads

3

Version

0.5.3

License

MIT

Unpacked Size

16.4 kB

Total Files

24

Last publish

Collaborators

  • alexaegis