Skip to content

Instantly share code, notes, and snippets.

View alexeisavca's full-sized avatar

Alexei Savca alexeisavca

View GitHub Profile
@alexeisavca
alexeisavca / headtail.js
Created July 11, 2015 07:59
JS head and tail
function head(arr){
return arr.slice(0, 1);
}
function tail(arr){
return arr.slice(1);
}
@alexeisavca
alexeisavca / pure-render-component.jsx
Last active August 29, 2015 14:23
Pure render component superclass(look, ma, no mixins!)
var React = require('react');
var shallowDiff = (a,b) => Object.keys(a).some(key => a[key] != b[key]);
module.exports = class extends React.Component {
shouldComponentUpdate (nextProps, nextState){
return shallowDiff(this.props, nextProps) || shallowDiff(this.state, nextState);
}
};
@alexeisavca
alexeisavca / placeholder-component
Created June 21, 2015 16:24
React placeholder. I like to develop my apps from top to bottom, so I use this often.
var React = require('react');
module.exports = function(name){
return class extends React.Component{
render(){
return (
<span>Implement {name}</span>
)
}
}
};
@alexeisavca
alexeisavca / obj2array.jsx
Last active August 29, 2015 14:20
obj2array
module.exports = function(obj){
return Object.keys(obj).map(function(key){
return obj[key];
});
};
@alexeisavca
alexeisavca / ReactIgnore
Last active March 12, 2023 12:24
A simple component to make ReactJs ignore subtrees
var React = require('react/addons');
var ReactIgnore = {
displayName: 'ReactIgnore',
shouldComponentUpdate (){
return false;
},
render (){
return React.Children.only(this.props.children);
}