Code coverage report for ReactFlux/lib/mixin.js

Statements: 100% (19 / 19)      Branches: 90.91% (10 / 11)      Functions: 100% (6 / 6)      Lines: 100% (19 / 19)      Ignored: none     

All files » ReactFlux/lib/ » mixin.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 461     1 9 9 1   8 8     8 2         6     3 3 2 1       3       3 3         1 1            
var _forEach = require('lodash-node/modern/collection/forEach');
 
 
module.exports = function(){
	var stores = Array.prototype.slice.call(arguments);
	if( !stores.length ){
		throw new Error('Flux.mixin expects a store or a list of stores');
	}
	_forEach(stores, function(store){
		var isNotOk = (
			typeof store === 'undefined' || typeof store.onChange !== 'function' || typeof store.offChange !== 'function'
		);
		if( isNotOk ){
			throw new Error('Flux.mixin expects a store or an array of stores');
		}
	});
 
 
	return {
 
		componentWillMount: function(){
			Eif( typeof this._react_flux_onChange === "undefined" ){
				this._react_flux_onChange = function() {
					if( this.isMounted() ){
						this.setState( this.getStateFromStores() );
					}
				}.bind(this);
			}
			this.setState( this.getStateFromStores() );
		},
 
		componentDidMount: function(){
			for(var i=0; i < stores.length; i++){
				stores[i].onChange(this._react_flux_onChange);
			}
		},
 
		componentWillUnmount: function(){
			for(var i=0; i < stores.length; i++){
				stores[i].offChange(this._react_flux_onChange);
			}
		}
	};
 
};