Last active
November 1, 2016 16:56
-
-
Save HyphnKnight/b27ed0e01b5039cb49800bea2ecc6738 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react-lite'; | |
| import { | |
| isUndefined, | |
| isString, | |
| isBoolean, | |
| isEqual, | |
| objectFind | |
| } from './functional'; | |
| class Reflex extends React.Component { | |
| constructor() { | |
| super(); | |
| this.state = {}; | |
| } | |
| shouldComponentUpdate( nextProps, nextState ) { | |
| if ( !!objectFind( nextState, ( stateValue, stateName ) => isUndefined( this.state[stateName] ) ) ) { | |
| throw 'Reflex - Attempting to set value of unregistered key.' | |
| } | |
| return !!objectFind( nextProps, ( propValue, propName ) => !isEqual( this.props[propName], propsValue ) ) || | |
| !!objectFind( nextState, ( stateValue, stateName ) => !isEqual( this.state[stateName], stateValue ) ); | |
| } | |
| generateClasses( ...propertyNames ) { | |
| let cssClasses = ''; | |
| propertyNames.forEach( name => { | |
| if ( !isUndefined( this.state[ name ]) ) { | |
| if ( isBoolean( this.state[ name ] ) ) { | |
| if ( !!this.state[ name ] ) { | |
| cssClasses += ` state-${name}`; | |
| } | |
| } else if ( isString( this.state[ name ] ) ) { | |
| cssClasses += ` state-${name}-${this.state[ name ]}`; | |
| } | |
| } else { | |
| throw 'Reflex - Attempting to create class from unregistered key'; | |
| } | |
| } ); | |
| return cssClasses; | |
| } | |
| } | |
| export default Reflex; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment