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

store-state-mixin

v0.1.7

Published

A React mixin for easily adding (flux) stores state to a component.

Downloads

4

Readme

#THIS REPO IS ABANDONED

With so many better and amazing tools available to pass down state in React today, this is rather pointless to use.

A React mixin for easily adding (flux) stores state to a component.

  • Efficiently updates component state, only for the stores that changed
  • Installs listeners on componentDidMount
  • Removes listeners on componentWillUnmount
  • No dependencies
  • Made for Alt, but might be useful with some other React stores as well

--

Usage:

Install with npm: npm install --save store-state-mixin

A flux example with alt using store-state-mixin:

// TopLevelComponent.js

// require the mixin and child components
const StoreStateMixin		= require( 'store-state-mixin' );
const SomeChildComponent	= require( './SomeChildComponent.js' );
const OtherChildComponent	= require( './OtherChildComponent.js' );


// create a stores init object for the mixin, using key names that will be
// used as keys in this component's state and child components props
const stores= {
	 someStore	: require( './stores/someStore.js' )
	,otherStore	: require( './stores/otherStore.js' )
};

const TopLevelComponent= React.createClass({

	 // add stores state and updates to component by mixin
	 mixins: [ StoreStateMixin(stores) ]

	,render: function(){

		// provide child components with stores state
		return (
			<div>
				<SomeChildComponent {...this.state} />
				<OtherChildComponent {...this.state} />
			</div>
		);
	}
});
export default TopLevelComponent;

In your child component:

// SomeChildComponent.js

// get your actions
const someActions= require( './actions/someActions.js' );

const SomeChildComponent= React.createClass({

	componentWillMount: function(){
		if ( ! this.props.someStore.info ){
			someActions.setInfo( 'Hello World!' );
		}
	}

	,render: function(){

		return (
			<div>
				{ this.props.someStore.info }
				// Hello World!
			</div>
		);
	}
});
export default SomeChildComponent;

The store:

// someStore.js

// refer to a alt instance and this store's actions
import alt           from './instance/alt.js';
import someActions	from './actions/someActions.js';

class SomeStore {

	constructor(){
		this.bindListeners({
			 setInfo: someActions.SET_INFO
		});
	}

	setInfo( info ){
		this.info= info;
	}
}
export default alt.createStore( SomeStore, 'someStore' );

The actions:

// someActions.js

import alt from './instance/alt.js'

class SomeActions {

	setInfo( info ){
		this.dispatch( info );
	}
}
export default alt.createActions( SomeActions );

A single Alt instance:

// alt.js
const alt= new require( 'alt' );
export default alt

Just to complete the example:

// OtherChildComponent.js

export default null
// otherStore

import alt           from './instance/alt.js';

class OtherStore {

}

export default alt.createStore( OtherStore, 'otherStore' );

--

0.1.5:

  • changes license to MIT

--

0.1.4:

  • replaces map with map-x

--

0.1.3:

  • added minified version
  • updated the readme
  • added example files

--

0.1.2:

  • adds hasOwnProperty to object map
  • adds es3 compatibility

###license

MIT