npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reactivehooks

v0.0.7

Published

Reactive Extensions helpers for React Hooks

Downloads

3

Readme

Reactive Hooks

npm version Build Status Coverage Status

Reactive Hooks provides a set of tools for work with Reactive Extensions in React using hooks

** This project is in a very early stage, feel free to contribute 😉

Click here to check an online working SAMPLE

Installation

Nothing new here, just npm install

npm i reactivehooks

Get Started

The code below is a sample that shows how to write a type ahead search using Reactive Hooks and RxJs:

// api fetch that returns an observable
const searchStarWarsPeople = (name: string) =>
      fetchJson<StarWarApiPeopleResult>(`https://swapi.co/api/people/?format=json&search=${name}`)

// create an input text that has obsevable properties
const SearchText = rxInput("text")
const loader = createLoaderControl() // loader control

// Rx operator pipeline for type ahead search
const typeAheadSearch$ =
  SearchText.onValueChanges$.pipe(
    filter(x => x.length >= 2),
    debounceTime(300),
    distinctUntilChanged(),
    loader.start(),
    switchMap(searchStarWarsPeople),
    retry(3),
    map(x => x.results),
    loader.stop(),
  )

const App = () => {
  // use observables
  const starWarsPeople = useObservable(typeAheadSearch$, [])
  const isLoading = useObservable(loader.status$, false)
  
  return (
    <div>
      <header>
        <SearchText  />
        {isLoading && <span>loading...</span>}
        <ul>
          {starWarsPeople.map((x, i) =>
            <li key={i}>
              <div>{x.name}</div>
            </li>
          )}
        </ul>
      </header>
    </div>
  )
}

Documentation

useSubscribe

A hook that provides a way to just subscribe to an observable

Signature:

 function useSubscribe<T>(
   observable: Observable<T>, 
   next?: ((value: T) => void), 
   error?: ((error: any) => void), 
   complete?: ((done: boolean) => void)
 ): void

useObservable

A hook that subscribes to an observable and returns the emited value as a state for your component

Signature:

function useObservable<T>(
    observable: Observable<T>, 
    initialValue: T
): T

useObservableWithError

A hook that subscribes to an observable and returns the emited value, error or complete as a state for your component

Signature:

function useObservableWithError<T>(
    observable: Observable<T>, 
    initialValue: T
): [T, any, boolean]

useRxInputValue

A hook that subscribes to an observable of changes of a RxInput, returning the value and a function to change the input value

Signature:

function useRxInputValue(
  rxInput: RxInput, 
  initialValue: string
) => [string, (value: string) => void]

rxInput

Creates a html input of given type, the control have observable properties for control changes

Signature:

function rxInput(type: string): RxInput

Properties

| Property | Event | Notes | |-----------------|----------|----------------------------------------------------------------------| | onChange$ | onChange | | | onFocus$ | onFocus | | | onBlur$ | onBlur | | | onValueChanges$ | onChange | Emit just the value of the control without the complete event object |

rxButton

Creates a html button, the control have observable properties for control changes

Signature:

function rxButton(): RxButton

Properties

| Property | Event | Notes | |-----------------|----------|----------------------------------------------------------------------| | onClick$ | onClick | |


createLoaderControl

Creates a helper object with RxJs operators for start and stop a loader observable

Signature:

function createLoaderControl(): {
    start(): function<T>(x: Observable<T>): Observable<T>;
    stop(): function<T>(x: Observable<T>): Observable<T>;
    status$: Observable<boolean>
}

fetchJson

Is just the fromFetch from rxjs/fetch, but auto map to json()

Signature:

function fetchJson<T>(
  url: string | Request, 
  init?: RequestInit
): Observable<T>