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

kefir-store

v1.6.5

Published

Observable store with handy declarative syntax

Downloads

17

Readme

kefir-store

Observable store with handy declarative syntax

Built on top of Kefir library.

install

npm i -S kefir-store

Motivation

We all know that observables are great. Indeed, they are. Reading about them, you'll probably find that rapturous articles about "how simple everything is with them". Need to deal with DOM events? Just do .fromEvent(myNode, "click"). Need some state and incremental updates? Just use .scan, and you're done! Validation? .filter(isEmail). And so on.

But hey. How about something more realistic than examples of particular operators? What if there are several sources which should update the same state in different ways? What if validator needs not just a value but also some fields from entire current state? What if you need to perform async update in .scan? What if you're using React – do you really each time will fall to lifecycle hooks, to call .fromEvent on DOM node in DidMount, and dispose stream in WillUnmount? Etc., etc., etc.

I'm sure all this can be solved (and is solved by someone) relatively easy. But so far I didn't found any system solution. Each time it's up to you, and you end up with a lot of boilerplate. So I tried to create such solution myself.

tl;dr

What this lib actually does is takes this pattern:

Kefir.merge([
  a$.map(x => ({ type: "A", value: x })),
  b$.map(x => ({ type: "B", value: x })),
  c$.map(x => ({ type: "C", value: x })),
  ...
]).scan((state, patch) => {
  if (patch.type === "A") {
    return updateA(state, patch.value)
  }
  
  if (patch.type === "B") {
    ...
  }
  
  ...
}, seed)

and turns it into this:

import { Stream } from "kefir-store"

Stream([
  [ a$, updateA ],
  [ b$, updateB ],
  ...
], seed)

, also providing a lot of extra advantages.

API

Package exports following functions:

  • Stream – basic entity. Start reading here.
  • Model – Stream + ability to push to it imperatively.
  • Form – Model + validation.
  • Subject – tiny wrapper around kefir-bus.
  • listReducer – helper to deal with collections in state.
  • setConfig – allows to override some parts of global behaviour.

How big is it?

$ cd node_modules/kefir-store
$ npm run measure

PATH                      SIZE     %
../kefir-store.js         66.7 kB  59%
../kefir-store.js.gz      11.8 kB  10%
../kefir-store.min.js     28.7 kB  25%
../kefir-store.min.js.gz  6.45 kB  6%

of course, .gz files aren't included in package. They are generated here just to show what will be really sent over network.

Why Kefir, why not ${my_favourite_FRP_lib}?

I found it very easy to use and to do what I actually want. It's written to be used by people, not to just be ideologically perfect.

I would be happy to make kefir-store able to use different FRP-libs as background (like amazing recompose does), but I'm definitely not able to do it myself, at least for now. If you feel such power inside you, any help is welcome.

License

MIT