Skip to content

Instantly share code, notes, and snippets.

@jquense
jquense / app.js
Last active August 29, 2015 14:26
implementation of redux's combineReducers adding flux waitFor()
import { createStore } from 'redux';
import combineReducers from './combineReducers';
let Store = createStore(combineReducers({
reducerA(state = 0, action, waitFor){
if ( action.type === 'TEST'){
waitState = waitFor(waitFor.reducerB)
if ( waitState.reducerB === 5 )
state = 10
function fetchSiteStatus(){
//pretend this is being fetched from a server
return {
type: 'FETCH_SITE_STATUS'
payload: { currentStatus: 'awesome', currentUser: 'John', lastLogin: new Date() }
}
}
function fetchStatuses(){
@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;
}
@jquense
jquense / entry.js
Created May 17, 2015 21:18
webpack with globalize
var Globalize = require('globalize')
@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(){
class MyComboBox extends React.Component {
constructor(props, context){
super(props, context)
this.state = { value: props.value }
}
componentWillReceiveProps(props){
this.setState({ value: props.value })
function chain(fnA, fnB){
return function(){
fnA && fnA.apply(this, arguments)
fnB && fnB.apply(this, arguments)
}
}
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">
@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()
});
// 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)