0.0.1 • Published 11 months ago

mini-rx v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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

0.0.1

11 months ago

0.0.0-dev.5

11 months ago

0.0.0-dev.4

11 months ago

0.0.0-dev.3

11 months ago

0.0.0-dev.2

11 months ago

0.0.0-dev.1

11 months ago