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

@sunny-g/rx-utils

v2.0.0-beta.1

Published

High-level RxJS utils

Downloads

2

Readme

RxJS utils

Documentation in progress... :turtle:

High-level RxJS utils built to be used with bind operator (::, proposal stage). Use library to increase readability and decrease code size for complex reactive dependencies.

API for state helpers is built around Functional Reducer pattern.

Notes

Observable is aliased as $ for brevity.

Sample 1

derived.flags
  .sample(derived.flags.map((fs) => fs.winGame)
  .filter(identity)).map((_) => (s) => assoc("ended", "win", s))

// =>

derived.flags
  ::atTrue("winGame")
  ::setState("ended", "win")

Sample 2

$
  .combineLatest(src.navi, state2, derived.flags)
  .debounce(1)
  .map([src.navi, state2, derived.flags], gameView)

// =>

render(gameView, [src.navi, state2, derived.flags]),

Sample 3

let errors = store(seeds, $.merge(
  state.map((s) => s.user.points).skip(1).map((x) => validate(Points)).map((p) => (s) => assocPath(["user", "points"], p, s)),
  state.map((s) => s.user.bonus).skip(1).map((x) => validate(Bonus)).map((p) => (s) => assocPath(["user", "points"], p, s))
))

// =>

let errors = store(seeds, $.merge(
  state::view("user.points").skip(1).map((x) => validate(Points))::toState("user.points"),
  state::view("user.bonus").skip(1).map((x) => validate(Bonus))::toState("user.bonus")
))

Install

$ npm install babel-preset-es2016
$ npm install babel-plugin-syntax-function-bind
$ npm install babel-plugin-transform-function-bind
$ npm install rx
$ npm install ramda
$ npm install rx-utils

Add to .babelrc:

{
  "plugins": [
    "syntax-function-bind",
    "transform-function-bind"
  ],
  "presets": [
    "es2016"
  ]
}

Use

let {view} = require("rx-utils")

let userEmailStream = stateStream::view("user.email")

API

$ u type for this variable (u for "upstream") is implied and omitted for brevity.

State

store

Canonical state reducer.

scan(...) + distinctUntilChanged() + shareReplay(1)

Example
update::store(...)

history

Make observable of n last upstream values.

this + scan + distinctUntilChanged() + shareReplay(1)

Example
state::history(...)

derive

Derive a state observable from a state observable.

combineLatest(...) + distinctUntilChanged() + shareReplay(1)

Example
derive(...)

deriveN

Derive a state observable from state observables.

this + combineLatest(...) + distinctUntilChanged() + shareReplay(1)

Example
deriveN(...)

Lensing

pluck

Make an observable of fragments of upstream values. Like native .pluck with nested path support.

Example
intent::pluck("parentNode.dataset")

pluckN

Make an observable of a fragment of upstream values.

Example
intent::pluckN(["parentNode.dataset1", "parentNode.dataset2"])

view

Make an observable of a state fragment. pluck(...) + distinctUntilChanged() + shareReplay(1)

Example
state::view("user.email")

viewN

Make an observable of state fragments. pluckN(...) + distinctUntilChanged() + shareReplay(1)

Example
state::viewN(["user.password", "user.passwordAgain"])

toOverState : String, (u -> (sf -> sf)) -> $ (s -> s)

Apply function to upstream value, apply resulting function to state fragment.

Example
// createUser : $ User
createUser::toOverState("users", (u) => assoc(u.id, u))
// ==
// createUser : $ User
createUser.map((u) => (s) => assocPath(["users", u.id], u, s))

toSetState : String, (sf -> sf) -> $ (s -> s)

Apply function to upstream value, replace state fragment with resulting value.

Example
// resetUsers : $ User
resetUsers::toSetState("users", (us) => map(..., us))
// ==
resetUsers.map((us) => (s) => assoc("users", map(..., us), s))

overState : String, (sf -> sf) -> $ (s -> s)

Apply function to state fragment. Upstream value does not matter.

Example
// increment : $ Boolean
increment::overState("counter", (c) => c + 1)
// ==
increment.map((_) => (s) => assoc("counter", s.counter + 1, s))

setState : String, v -> $ (s -> s)

Replace state fragment with a value. Upstream value does not matter.

Example
// reset : $ Boolean
resetForm::setState("form", seedForm)
// ==
resetForm.map((_) => (s) => assoc("form", seedForm, s))

toState : String -> $ (s -> s)

Replace state fragment with upstream value.

Example
// changeUsername : $ String
changeUsername::toState("form.username"),
// ==
changeUsername.map((v) => (s) => assocPath(["form", "username"], v, s))

Filtering & sampling

filterBy

Filter observable by another observable (true = keep).

Example
intent::filterBy(...)

rejectBy

Filter observable by another observable (true = drop).

Example
intent::rejectBy(...)

at

Pass upstream value futher if its fragment satisfies a predicate.

Example
flags::at(...)::overState(...)

atTrue

Pass upstream value futher if its fragment is true.

Example
flags::atTrue(...)::overState(...)

atFalse

Pass upstream value futher if its fragment is false.

Example
flags::atFalse(...)::overState(...)

Other

render

Apply a function over observable values in a glitch-free way.

Example
let view$ = render(
  [ state$, props.get('displayText') ],
  ({ isLoading }, displayText) => (
    <div>
      {isLoading
        ? 'Loading...'
        : displayText
      }
    </div>
  ))