Skip to content

Instantly share code, notes, and snippets.

function isAllOf(validators){
return function(props, propName, componentName) {
var err;
validators.every( validator => {
err = validator(props, propName, componentName)
return !err
})
return err
@jquense
jquense / mixins.js
Created March 11, 2015 21:38
React mixin thing
function mixin(){
var privatevar = 5;
this.on('componentWillMount', () =>{
//stuff
})
this.mixinMethod = () => {
return privatevar;
}
// there are a few methods that you need to implement/override to create a new type
// The main one is `_coerce`, which passing in the raw value and returns the type back.
// _coerce should not throw errors, and should return the default invalid object for a type if it exists (NaN, etc)
//here is the date `_coerce()` (I need to change it to return an InvalidDate instead of null)
_coerce(value) {
if(value == null ) return value
if(isDate(value) ) return new Date(value)
@jquense
jquense / index.js
Created April 9, 2015 14:48
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var yup = require('yup')
var assert = require('assert')
var schema = yup.object({
name: yup.string(),
id: yup.string()
});
let FilterInput = React.createClass({
render: function() {
return (
<input className={this.props.className} placeholder=={this.props.placeholder} />
// or more terse
// <input {...this.props} />
);
});
<div className="row header">
function chain(fnA, fnB){
return function(){
fnA && fnA.apply(this, arguments)
fnB && fnB.apply(this, arguments)
}
}
class MyComboBox extends React.Component {
constructor(props, context){
super(props, context)
this.state = { value: props.value }
}
componentWillReceiveProps(props){
this.setState({ value: props.value })
@jquense
jquense / DisabledItemList.jsx
Last active August 29, 2015 14:19
DropdownList multiple disabled items
var DisabledList = React.createClass({
// proptypes tell the parent widget what to pass into it
// the DropdownList will inspect propTypes and _.pick() those keys to pass in
propTypes: {
disabledItems: React.PropTypes.array,
...List.type.propTypes,
},
componentWillMount(){
@jquense
jquense / entry.js
Created May 17, 2015 21:18
webpack with globalize
var Globalize = require('globalize')
@jquense
jquense / error-style.css
Last active August 29, 2015 14:21
Code mirror jsx mode
.cm-s-monokai .cm-tag.cm-error,
.cm-s-monokai .cm-bracket.cm-error {
color: #f92672;
background: transparent;
}