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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mongodb-js/reflux-state-mixin

v1.2.22

Published

Reflux stores mixin adding 'state' syntax similar to React components

Downloads

118

Readme

reflux-state-mixin

A mixin to make Reflux Stores to have a state, similar to React components.

Installation

$ npm install @mongodb-js/reflux-state-mixin --save

in store:

// myStore.js
var Reflux = require('reflux');
var StateMixin = require('reflux-state-mixin');
var Actions = require('./../actions/AnimalsActions');

var AnimalStore = (module.exports = Reflux.createStore({
  mixins: [StateMixin.store],
  listenables: Actions, //or any other way of listening...

  getInitialState: function () {
    //that's a must!
    return {
      dogs: 5,
      cats: 3,
    };
  },

  onNewDogBorn: function () {
    this.setState({ dogs: this.state.dogs + 1 });
    //just like in a Component.
    //this will `trigger()` this state, similar to `render()` in a Component
  },

  //you can use storeDidUpdate lifecycle in the store, which will get called with every change to the state
  storeDidUpdate: function (prevState) {
    if (this.state.dogs !== prevState.dogs) {
      console.log('number of dogs has changed!');
    }
  },
}));

in component:

1. the easy way - connect, with mixin or decorator:

// PetsComponent.js
var AnimalStore = require('./AnimalStore.js');
var StateMixin = require('reflux-state-mixin');

var PetsComponent = React.createClass({
    mixins:[
        StateMixin.connect(AnimalStore, 'dogs')
        StateMixin.connect(AnimalStore, 'cats')
        //OR
        StateMixin.connect(AnimalStore) //now PetsComponent.state includes AnimalStore.state
        ],

    render: function () {
        return (<div><p>We have {this.state.dogs + this.state.cats} pets</p></div>);
    }
})

and if you use React's es6 classes, use the es7 connector decorator:

import { connector } from 'reflux-state-mixin';
import { AnimalStore } from './AnimalStore';

//@viewPortDecorator // make sure other decorators that returns a Component (usually those who provide props) are above `connector` (since it controls state).
@connector(AnimalStore, 'cats')
@connector(AnimalStore, 'dogs')
//or the entire store
@connector(AnimalStore)
//@autobind //other decorators could be anywhere
class PetsComponent extends React.Component {
  render() {
    let { dogs, cats } = this.state;
    return <div>We have {dogs + cats} pets</div>;
  }
}

or if you want to take the long way:

listening to a specific property of Store's state
var AnimalStore = require('./AnimalStore.js');

var DogsComponent = React.createClass({
  mixins: [Reflux.ListenerMixin],
  getInitialState: function () {
    return {
      dogs: AnimalStore.state.dogs,
      //Treat store.state as immutable data - same as you treat component.state -
      //you could use it inside a component, but never change it's value - only with setState()
    };
  },
  componentDidMount: function () {
    this.listenTo(AnimalStore.dogs, this.updateDogs);
    //this Component has no interest in `cats` or any other animal, so it listens to `dogs` changes only
  },
  updateDogs: function (dogs) {
    this.setState({ dogs: dogs });
    //now we have auto-synchronization with `dogs`, with no need for specific logic for that
  },
  render: function () {
    return (
      <div>
        <p>We have {this.state.dogs} dogs</p>
      </div>
    );
  },
});
listen to an entire store:
var AnimalStore = require('./AnimalStore.js');

var PetsComponent = React.createClass({
  mixins: [Reflux.ListenerMixin],
  getInitialState: function () {
    return {
      dogs: AnimalStore.state.dogs,
      cats: AnimalStore.state.cats,
    };
  },
  componentDidMount: function () {
    this.listenTo(AnimalStore, (state) => {
      this.setState({
        dogs: state.dogs,
        cats: state.cats,
      });
    });
    //this way the component can easily decide what parts of the store-state are interesting
  },

  render: function () {
    return (
      <div>
        <p>We have {this.state.dogs + this.state.cats} pets</p>
      </div>
    );
  },
});

some details

GetInitialState() in store should have all of the states from the beginning. Store should not have any method that are declared in state, since you can listen to MyStore.dogs setState() is checking to see if there is a difference between new state.key from current state.key. If not, this specific state.key it's not triggering. For any setState() the entire store is triggering (regardless of changes), allowing any Component or other Store to listen to the entire Store's state.

acknowledgments

Original source from yonatanmn/Super-Simple-Reflux.

This mixin was inspired by (a.k.a shamelessly stole from) - triggerables-mixin. Also see this for details. reflux-provides-store And state-mixin.

I thank @jehoshua02 @brigand and @jesstelford for their valuable code.