New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rehooker

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rehooker

React state management powered by rxjs and react hooks.

  • 0.0.9
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

Rehooker

State management powered by rxjs and react hooks.

API

  • createStore(defaultState)

    • create a store with these methods:
      • getState()
        • get current state.
      • stream
        • get the rxjs observable of state.
      • next(Mutation):void
        • Mutation is (previousState)=>nextState
        • dispatch a mutation to change the current state.
  • useSink(operation:(sub:Subject<T>), dependencies: any[]): (value:T)=>void

    • a hook that creates a event handler which calls the underlying rxjs Subject's next()
    • dependencies is the underlying useEffect's second argument
  • useObservable(ob:Observable<T>): T

    • a hook which get the value of an observable
  • useSource(ob:Observable<T>, operator:(ob:Observable<T>)=>Observable<T> = x=>x, dependencies: any[])

    • a hook which do 3 things:
        1. apply the operator on an observable
        1. do shallow compare like react does
        1. get the value of an observable
    • dependencies is the underlying useEffect's second argument

Example

import {createStore, get, useSubject} from "guguder"
import * as React from "react"
import { Http } from './service/http';
import { from } from 'rxjs';
import { debounceTime, map, tap } from 'rxjs/operators';

const peopleStore = createStore([] as any[])

const http = Http("https://swapi.co/api",{
    headers:{
        'content-type':"application/json"
    }
},res=>res.json())

const getPeople = ()=>useSubject(
    v=>v.pipe(
        tap((e)=>{
            console.log(e)
        }),
        debounceTime(300),
        map(()=>from(http.get('/people/1/') as Promise<any[]>)),
    ).subscribe(v=>{
        peopleStore.dispatch(v.pipe(map(v=>()=>v)))
    })
)

export function App(){
    const people = get(peopleStore.stream)
    return <div>
        <button onClick={getPeople()}>getPeople</button>
        <pre>
            {JSON.stringify(people)}
        </pre>
    </div>
}

Keywords

FAQs

Package last updated on 09 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc