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 🙏

© 2025 – Pkg Stats / Ryan Hefner

rx-store

v1.0.0

Published

Reactive library for managing state

Downloads

17

Readme

npm version Build Status Dependency Status

rx-store

rx-store is a reactive solution for managing state. It is framework and view agnostic, though it can be used as the basis for a Flux pattern.

Installation

npm install --save rx-store

Usage

Import library

ES6

import {createRxStore} from 'rx-store';

ES5 with modules

var createRxStore = require('rx-store').createRxStore;

ES5

<script src="node_modules/rx-store/dist/rx-store.browser.min.js"></script>
// window.RxStore.createRxStore

Create a store

createRxStore takes a reduce function as an argument as well as an optional initial state. If not specified the initial state starts out as undefined. Note that the state can be any valid JS type (object, array, number, etc.).

function sum(previousState, nextState) {
  return previousState + nextState;
}
var initialState = 0;
var store = createRxStore(sum, initialState);

Subscribe to State Changes

store.subscribe(function(state) {
  // do stuff with state
});

// which is equivalent to

store.state$.subscribe(function(state) {
  // do stuff with state
});

Modify State

var action = 4;
store.dispatch(action);

store.subscribe(function(state) {
  console.log('State: ' + state);
});
// State: 0
// State: 4

Modify State from Browser Event

var addTwo$ = Rx.Observable.fromEvent(btnNode, 'click').map(e => {
  return 2;
});

// send each new action to the store
addTwo$.subscribe(function(action) {
  store.dispatch(action);
});

Using as a Flux Pattern

function reducer(state, action) {
  switch (action.type) {
    case 'ADD':
      var addState = state;
      addState.count += action.payload;
      return addState;
    case 'ACTION_TWO':
      return actionTwo(state);
    default:
      return state;
  }
}
var initialState = {count: 0, somethingElse: 'data'};
var store = createRxStore(reducer, initialState);

function add(data) {
  return {
    type: 'ADD',
    payload: data
  };
}

var addAction = add(4);
var addAction2 = add(-1);
store.dispatch(addAction);
store.dispatch(addAction2);

store.subscribe(function(data) {
  console.log(data);
});
// {count: 0, somethingElse: 'data'}
// {count: 4, somethingElse: 'data');
// {count: 3, somethingElse: 'data');

Using with React Views

class MyComponent extends React.Component {
  componentDidMount() {
    this.countSubscription = this.props.countStream.subscribe((count) => {
      this.setState({count: count});
    });
  }

  componentWillUnmount() {
    this.countSubscription.unsubscribe();
  }

  render() {
    return <div>{this.state.count}</div>;
  }
}

var count$ = store.state$.map(function(data) {
  return data.count;
});
ReactDOM.render(<MyComponent countStream={count$} />, domNode);