Skip to content

Instantly share code, notes, and snippets.

import React from 'react'
import ReactDOM from 'react-dom'
import { createStore, combineReducers } from 'redux'
import * as R from 'ramda'
// composition helper
const combine = R.curry((c, o) => x => (<div>{c(x)} {o(x)}</div>))
const combineComponents = (...args) => {
const [first, ...rest] = args
return R.reduce((acc, c) => combine(acc, c), first, rest)
// a basic example demonstrating the power of channels and generators
import React from 'react'
import { render } from 'react-dom'
import { chan, go, take, put, putAsync } from 'js-csp'
import { curry } from 'ramda'
import Counter from './Counter'
// helper
const createRender = curry((node, app) => render(app, node))
// create one channel for now
// A quick experiment with Channels and React
// this needs more thinking
// but might be useful as a starting point.
import React from 'react'
import { render } from 'react-dom'
import { chan, go, timeout, take, put, putAsync, buffers } from 'js-csp';
import { add, assoc, curry, compose, map, mapObjIndexed, max, pluck, prop, reduce } from 'ramda'
const initialState = {
@busypeoples
busypeoples / LoadUsers.elm
Created April 13, 2017 23:28
Elm Example - Side-Effects Handling
module LoadUsers exposing (..)
import Html exposing (Html, div, h1, text)
import Http
import Json.Decode as Decode
main =
Html.program
{ init = init
@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 / 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
const enhancedForm = Component =>
class HigherOrderComponent extends React.Component {
constructor(props) {
super(props)
this.state = { form: props.initialState }
this.handleSubmit = this.handleSubmit.bind(this)
this.handleChange = this.handleChange.bind(this)
}
handleSubmit(e) {
import React from 'react'
const enhancedForm = Component =>
class HigherOrderComponent extends React.Component {
constructor(props) {
super(props)
this.state = { form: props.initialState }
this.handleSubmit = this.handleSubmit.bind(this)
this.handleChange = this.handleChange.bind(this)
@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

import React from 'react'
import hoistNonReactStatics from 'hoist-non-react-statics'
import { assoc, assocPath, identity, is, map, prop } from 'ramda'
import isValid from './isValid'
// random helper function
// extract the needed information from the event
const getValueName = (e) => {
const target = e.target
const name = target.name