Skip to content

Instantly share code, notes, and snippets.

View nelix's full-sized avatar
🎯
Focusing

Nathan Hutchision nelix

🎯
Focusing
View GitHub Profile
var Immutable = require('devtools/client/shared/vendor/seamless-immutable');
var gentest = require('devtools/client/shared/vendor/gentest');
var types = gentest.types;
function maybe(type) {
return types.oneOf([type, types.constantly(null)]);
}
var foo = function () {
/*
* Top-level error handler for async functions.
*/
async function errorWrap(cb, ...args) {
try {
await cb(...args);
} catch(err) {
if (err.stack) {
// `Error` object
console.log(err.stack);
@threepointone
threepointone / sto.js
Created July 28, 2015 07:12
a lightweight flux style store as a component
import React from 'react';
export class Sto extends React.Component{
static defaultProps = {
store: x => x
}
state = {
value: this.props.store()
}
dispatch = action => this.setState({
@acdlite
acdlite / flux.js
Last active October 7, 2021 17:19
A Redux-like Flux implementation in <75 lines of code
/**
* Basic proof of concept.
* - Hot reloadable
* - Stateless stores
* - Stores and action creators interoperable with Redux.
*/
import React, { Component } from 'react';
export default function dispatch(store, atom, action) {
@threepointone
threepointone / index.js
Last active March 22, 2016 10:17
time travel with disto
import {Dis} from 'disto';
import {photo} from 'disto/record';
let {register, dispatch, lock, unlock} = new Dis();
let store = photo(register({x: 0}, o => ({x: o.x+1}))); // simple increments
store.subscribe(o => console.log(o.x)); // 0
let t1 = store.snapshot();
dispatch('xyz'); // 1
@jlongster
jlongster / forms-with-react.js
Last active May 8, 2017 14:15
higher-order form components w/react
// Simple wrapper to use bootstrap's grid system to position elements side-by-side
var VerticalFieldsElement = React.createClass({
render: function() {
return dom.div(
{ className: 'clearfix' },
React.Children.map(this.props.children, function(child) {
if(!child) {
return child;
}
"use strict";
var [BRA, KET, IDENT] = ['BRA', 'KET', 'IDENT'];
function last(arr){ return arr[arr.length -1] };
export default function act(src, prefix){
var tree = src.split('').reduce((tokens, char)=> {
if(char==='{'){
tokens.push({type: BRA});
@mattdesl
mattdesl / debugger.js
Last active December 30, 2015 03:53
bug with setScriptSource ?
var Chrome = require('chrome-remote-interface')
Chrome({
chooseTab: function(tabs) {
var idx = 0
tabs.forEach(function(tab, i) {
if (tab.url === 'http://localhost:9966/')
idx = i
})
return idx
@bendc
bendc / functional-utils.js
Last active September 15, 2023 12:12
A set of pure ES2015 functions aimed to make functional JavaScript more idiomatic.
// array utils
// =================================================================================================
const combine = (...arrays) => [].concat(...arrays);
const compact = arr => arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)
@threepointone
threepointone / oia_csp.js
Last active March 22, 2016 10:19
an implementation of rob pike's parallel search slide in oia
oia(lets [go chan put take timeout alts] (require 'js-csp/lib/csp') (do
(fn fake [kind]
(fn [c query]
(go (gen []
(yield (take (timeout (js Math.random()*200))))
(yield (put c [kind query]))))))
(def web1 (fake :web1))
(def web2 (fake :web2))