Skip to content

Instantly share code, notes, and snippets.

@jquense
jquense / connect.js
Last active March 3, 2016 16:14
code splitting with redux
export function connect(...stores) {
let filter = s => s;
if (!stores[stores.length - 1].__reduxName)
filter = stores.pop();
let connector = reduxConnect(
filter.length > 1
? (state, props) => filter(storesState(state, stores), props)
: (state) => filter(storesState(state, stores))
@jquense
jquense / webpack helpers.js
Created January 5, 2016 17:10
in mempory webpack testing
export function run(config, assert) {
return new Promise((resolve, reject) => {
let compiler = webpack(config)
let fs = compiler.outputFileSystem = new MemoryFileSystem();
compiler.run(function (err, stats) {
if (err) return reject(err)
let errors = stats.compilation.errors || [];
if (assert) expect(errors.length).to.equal(0, errors.join('\n'))
class Tab {
static childContextTypes = {
registerHook: PropTypes.func
}
constructor() {
super()
this._hooks = []
}
@jquense
jquense / react-widgets-virtual-list.js
Created September 25, 2015 11:19
Custom List Component
import React from 'react';
import ListMovementMixin from 'react-widgets/lib/mixins/ListMovementMixin';
import List from 'react-widgets/lib/List';
import ListOption from 'react-widgets/lib/ListOption';
import { dataText } from 'react-widgets/lib/util/dataHelpers';
import cn from 'classnames';
import BaseVirtualList from 'react-list';
let VirtualList = React.createClass({
@jquense
jquense / routing.js
Created September 14, 2015 04:56
React router with areas and names
import React from 'react';
import { Router as BaseRouter } from 'react-router';
import { getParamNames, formatPattern } from 'react-router/lib/PatternUtils';
import { createRoutes } from 'react-router/lib/RouteUtils'
import createBrowserHistory from 'history/lib/createBrowserHistory';
import useBeforeUnload from 'history/lib/useBeforeUnload';
import invariant from 'app/utils/invariant';
import { each, pick, omit, sortBy } from 'lodash';
const EMPTY_AREA = '@@none';
@jquense
jquense / App.js
Created August 24, 2015 20:00
double react-dom
import React from 'react';
import { render, findDOMNode } from 'react-dom'
render(<div/>, document.getElementById('root'))
@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 / jsx-mode.js
Last active October 17, 2015 05:40
An attempt at a jsx CodeMirror mode
/*global CodeMirror */
function indexOf(string, pattern, from) {
if (typeof pattern === "string") {
var found = string.indexOf(pattern, from);
return found;
}
var m = pattern.exec(from ? string.slice(from) : string);
return m ? (m.index + from) : -1;
}
@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;
}