ProductPromotion
Logo

Angular.JS

made by https://0x3d.site

GitHub - chrisguttandin/subscribable-things: A collection of reactive wrappers for various browser APIs.
A collection of reactive wrappers for various browser APIs. - chrisguttandin/subscribable-things
Visit Site

GitHub - chrisguttandin/subscribable-things: A collection of reactive wrappers for various browser APIs.

GitHub - chrisguttandin/subscribable-things: A collection of reactive wrappers for various browser APIs.

logo

subscribable-things

A collection of reactive wrappers for various browser APIs.

version

This package provides factory functions which can be used to turn browser APIs into subscribable things. A subscribable thing can either be consumed directly with callback functions or by utilzing one of the popular libraries for reactive programming.

Usage

The subscribable-things package is published on npm and can be installed as usual.

npm install subscribable-things

It exports individual functions for each wrapped browser API which are described in greater detail below. They can either be used directly by providing a callback function ...

import { mediaQueryMatch } from 'subscribable-things';

const subscribe = mediaQueryMatch('(max-width:600px)');

const unsubscribe = subscribe((isMatching) => console.log(isMatching));

unsubscribe();

... or by utilizing a library for reactive programming like RxJS ...

import { from } from 'rxjs';
import { mediaQueryMatch } from 'subscribable-things';

const mediaQueryMatch$ = from(mediaQueryMatch('(max-width:600px)'));

const subscription = mediaQueryMatch$.subscribe((isMatching) => console.log(isMatching));

subscription.unsubscribe();

... or Callbags ...

import fromObs from 'callbag-from-obs';
import observe from 'callbag-observe';
import { mediaQueryMatch } from 'subscribable-things';

const source = fromObs(mediaQueryMatch('(max-width:600px)'));

observe((isMatching) => console.log(isMatching))(source);

... or XStream ...

import { mediaQueryMatch } from 'subscribable-things';
import { fromObservable } from 'xstream';

const stream = fromObservable(mediaQueryMatch('(max-width:600px)'));

const unsubscribe = stream.subscribe((isMatching) => console.log(isMatching));

unsubscribe();

... or Bacon.js ...

import { fromESObservable } from 'baconjs';
import { mediaQueryMatch } from 'subscribable-things';

const eventStream = fromESObservable(mediaQueryMatch('(max-width:600px)'));

const unsubscribe = eventStream.onValue((isMatching) => console.log(isMatching));

unsubscribe();

... or Kefir.js.

import { fromESObservable } from 'kefir';
import { mediaQueryMatch } from 'subscribable-things';

const stream = fromESObservable(mediaQueryMatch('(max-width:600px)'));

const subscription = stream.observe({
    value(isMatching) {
        console.log(isMatching);
    }
});

subscription.unsubscribe();

It is even possible to consume subscribable-things as an async iterable by taking the little detour over RxJS and rxjs-for-await.

import { eachValueFrom } from 'rxjs-for-await';
import { from } from 'rxjs';
import { mediaQueryMatch } from 'subscribable-things';

const source$ = from(mediaQueryMatch('(max-width:600px)'));

for await (const isMatching of eachValueFrom(source$)) {
    console.log(isMatching);
}

Also it's possible to output values directly to HTML via hyperf.

import h from 'hyperf';
import { mediaQueryMatch } from 'subscribable-things';

const element = h`<div>is matching: ${mediaQueryMatch('(max-width:600px)')}</div>`;

document.body.appendChild(element);

animationFrame()

function animationFrame(): SubscribableThing<number>;

This function wraps the requestAnimationFrame() method. It emits the current timestamp of each animation frame.

attribute(htmlElement, name)

function attribute(htmlElement: HTMLElement, name: string): TSubscribableThing<null | string>;

This function uses mutations() on the inside to emit the latest value of the attribute with the given name.

geolocation([options])

function geolocation(options?: PositionOptions): SubscribableThing<GeolocationPosition>;

This is a wrapper for the Geolocation API. It uses watchPosition() to gather the most recent GeolocationPosition whenever it changes.

intersections(htmlElement, [options])

function intersections(
    htmlElement: HTMLElement,
    options?: IntersectionObserverInit
): SubscribableThing<IntersectionObserverEntry[]>;

This function is a wrapper for the IntersectionObserver.

mediaDevices()

function mediaDevices(): SubscribableThing<MediaDeviceInfo[]>;

This function is a wrapper for the enumerateDevices() method of the Media Capture and Streams specification. It will also listen for the devicechange event to emit a fresh list of devices whenever they change.

mediaQueryMatch(mediaQueryString)

function mediaQueryMatch(mediaQueryString: string): SubscribableThing<boolean>;

This function is a wrapper for the matchMedia() method. It will emit a new value whenever the result of matchMedia() changes.

midiInputs(midiAccess)

function midiInputs(midiAccess: IMidiAccess): SubscribableThing<IMidiInput[]>;

This function returns the currently available MIDI input devices. It accepts a MIDIAccess object of the Web MIDI API.

midiOutputs(midiAccess)

function midiOutputs(midiAccess: IMidiAccess): SubscribableThing<IMidiOutput[]>;

This function returns the currently available MIDI output devices. It accepts a MIDIAccess object of the Web MIDI API.

metrics(options)

function metrics(options: PerformanceObserverInit): SubscribableThing<PerformanceEntry[]>;

This function is a wrapper for the PerformanceObserver as defined by the Performance Timeline Level 2 specification.

mutations(htmlElement, options)

function mutations(
    htmlElement: HTMLElement,
    options: MutationObserverInit
): SubscribableThing<MutationRecord[]>;

This function is a wrapper for the MutationObserver.

on(target, type, [options])

function on(
    target: EventTarget,
    type: string,
    options?: boolean | AddEventListenerOptions
): SubscribableThing<Event>;

This function can be used to subscribe to events of a certain type dispatched from an EventTarget.

online()

function online(): SubscribableThing<boolean>;

This function wraps the onLine property of the Navigator and listens for the corresponding 'online' and 'offline' events on the Window to emit updates.

permissionState(permissionDescriptor)

function permissionState(
    permissionDescriptor: PermissionDescriptor
): SubscribableThing<PermissionState>;

This function is a wrapper for the query() method of the Permissions API. It will monitor the permission status to emit a new state whenever it gets updated.

reports([options])

function reports(options?: IReportingObserverOptions): SubscribableThing<IReport[]>;

This function is a wrapper for the ReportingObserver of the Reporting API.

resizes(htmlElement, [options])

function resizes(
    htmlElement: HTMLElement,
    options?: IResizesObserverOptions
): SubscribableThing<IResizeObserverEntry[]>;

This function is a wrapper for the ResizeObserver of the Resize Observer specification.

unhandledRejection(coolingOffPeriod)

function unhandledRejection(coolingOffPeriod: number): SubscribableThing<any>;

This function emits unhandled rejections. It will listen for the unhandledrejection event to register possibly unhandled rejections. It will then wait for the cooling-off period to elapse before it emits the reason (aka the error) that caused the unhandled rejection. It is possible that a previously unhandled rejection gets handled later on in which case a rejectionhandled event will be fired. If that happens during the cooling-off period nothing will be emitted by this function.

videoFrame(videoElement)

function videoFrame(
    videoElement: HTMLVideoElement
): SubscribableThing<{ now: number } & IVideoFrameMetadata>;

This function wraps the requestVideoFrameCallback() method of the given HTMLVideoElement. It emits the current timestamp combined with the VideoFrameMetadata object.

wakeLock(type)

function wakeLock(type: TWakeLockType): SubscribableThing<boolen>;

This function simplifies the usage of the Screen Wake Lock API. It emits true when a wake lock could be acquired and emits false once the wake lock gets released by the browser. As long as the subscription is alive it will continuosly try to get a new wake lock if the current one gets released.

Alternatives

There are two similar packages available which are based directly on RxJS. They are rx-use and rxjs-web.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory