Skip to content

Instantly share code, notes, and snippets.

@busypeoples
busypeoples / nestedMap.js
Last active August 14, 2017 12:46
nest map for ramda
import {
ifElse,
map,
partial,
} from 'ramda'
const isObject = input => typeof input === 'object'
/**
* Like map but for deeply nested objects
// Why the Hipsters Reduce Everything!
// Map implementation
import R from 'ramda'
const map = (f, data) =>
R.reduce((xs, x) => {
return [...xs, f(x)]
}, [], data)
@busypeoples
busypeoples / Flow_Chapter_Two.md
Last active September 5, 2017 14:29
Chapter 2: Using Flow

Back To The Basics

Chapter 2: Using Flow

Introduction

Why does it make sense to use FlowType or TypeScript when working with JavaScript? To give an appropriate answer, the best idea would be to build a small game or application to make the benefits clear.

@busypeoples
busypeoples / validateSpec.js
Last active September 27, 2017 18:08
Validate deeply nested inputs.
const R = require('ramda')
const colors = ['green', 'blue', 'red']
const notEmpty = R.compose(R.not, R.isEmpty)
const minLength = a => b => R.length(b) > a
const hasPresetColors = x => R.indexOf(x, colors) !== -1
const input = {
id: 1,
userName: 'Random',
@busypeoples
busypeoples / README.md
Last active October 3, 2017 05:00
setSateHigherOrderComponent for combining stateless functions with setState functions on the fly.

SetState React HigherOrderComponent

Why?

If you want to write stateless functions in React and need to combine a number of setState functions to that stateless function. Enables to compose a number of functions expecting state and props. This enables to reuse functions when needed and eases testing those functions (as they are standalone and decoupled from React.

Example

const fakeFetch = () =>
new Promise((res, rej) => {
setTimeout(
() =>
res([
{ id: 1, name: 'foo' },
{ id: 2, name: 'bar' },
{ id: 3, name: 'baz' }
]),
1000
@busypeoples
busypeoples / Loader.js
Created November 4, 2017 13:09
Loader Implementation
import React from 'react';
import daggy from 'daggy';
// Inspired by:
// "Slaying a UI Antipattern in Fantasyland" @thinkfunctional
// https://medium.com/javascript-inside/slaying-a-ui-antipattern-in-fantasyland-907cbc322d2a
// "Use a Render Prop!"
// https://cdb.reacttraining.com/use-a-render-prop-50de598f11ce @mjackson
@busypeoples
busypeoples / package.json
Last active December 20, 2017 13:37
Testing in React: Basic Examples + Setup
{
"name": "example-karma-jasmine-webapck-test-setup",
"description": "React Test Setup with Karma/Jasmine/Webpack",
"scripts": {
"test": "karma start --single-run --browsers PhantomJS"
},
"devDependencies": {
"babel": "^6.5.2",
"babel-core": "^6.5.2",
"babel-eslint": "^5.0.0",
@busypeoples
busypeoples / Game.re
Last active January 7, 2018 22:08
ReasonML Game
type field =
| O
| X;
type position = (field, field, field, field);
type unit = (position, position, position, position);
type units = list(unit);
@busypeoples
busypeoples / ReactGame.js
Last active January 16, 2018 08:10
ReactGame Example: React + Flow
// @flow
import React from 'react';
import { render } from 'react-dom';
type Field = 0 | 1;
type Position = [Field, Field, Field, Field];
type Unit = [Position, Position, Position, Position];