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

0.0.1 • Public • Published

A small barebones reactive library built for a stripped back observable primitive. The api and method names are borrowed from rxjs.

Build Status Build Size Version Downloads

npm install mini-rx # or yarn add mini-rx or pnpm add mini-rx

Observable

Unlike rxjs this observable provides no error pathway and never completes.

type Observable<T> = (subscriber: (x: T) => void): () => void

Usage

import { pipe, merge, map, of, switchMap, fromEvent  } from 'mini-rx'

const box = document.getElementById('#box')!;

const $pointer_over = pipe(
  merge(
    pipe(fromEvent(box, 'pointerenter'), map(() => true)),
    pipe(fromEvent(box, 'pointerleave'), map(() => false))
  ),
)

// Get the pointer position when pointer is over box
const $pointer_position = pipe(
  $pointer_over,
  switchMap(is_over => is_over ? fromEvent(box, 'pointermove') : of()),
  map(e => ({ x: e.clientX, y: e.clientY }))
)

// Subscribe to events
$pointer_over((x: boolean) => ...)
$pointer_position((x: { x: nunber, y: number }) => ...)

License

MIT © Dan Beaven

Package Sidebar

Install

npm i mini-rx

Weekly Downloads

0

Version

0.0.1

License

MIT

Unpacked Size

60.3 kB

Total Files

47

Last publish

Collaborators

  • pingid