Skip to content

Instantly share code, notes, and snippets.

View phpsmarter's full-sized avatar

ReactSmarter phpsmarter

View GitHub Profile
@jperasmus
jperasmus / compose.js
Last active June 30, 2022 07:48
"compose" function that handles both sync and async functions
// Async compose
const compose = (…functions) => input => functions.reduceRight((chain, func) => chain.then(func), Promise.resolve(input));
// Functions fn1, fn2, fn3 can be standard synchronous functions or return a Promise
compose(fn3, fn2, fn1)(input).then(result => console.log(`Do with the ${result} as you please`))
@renso3x
renso3x / rn-compose-login.js
Created August 2, 2017 13:17
Recompose RN login form
import React from 'react';
import PropTypes from 'prop-types';
import {
compose,
withHandlers,
withState,
setStatic,
setPropTypes
} from 'recompose';
import { View } from 'react-native';
@export-mike
export-mike / compose-async.js
Last active June 30, 2020 22:30
compose utility function for async await, A team effort with @cameronbourke and @gwyneplaine. It was a fun discussion.
/*
* Requires Node 8+
* Works in chrome, simply copy and paste into console.
*/
const R = require('ramda');
const compose =
(...funcs) =>
(...args) =>
funcs.reduceRight(async (a, f) => {
@pokorson
pokorson / list.js
Last active January 16, 2018 09:53
List stateless with recompose
import React from "react";
import { pure, withReducer, compose, withHandlers, mapProps } from "recompose";
import R from "ramda";
import { createReducer } from "./utils";
const ListItem = pure(({ text }) => <li>{text}</li>);
const renderItems = R.map(t => <ListItem key={t} text={t} />);
const ListComponent = ({ todos, name, updateName, addTodo }) =>
<div>
@idkjs
idkjs / import-books.js
Created June 15, 2017 17:52
books-recompose import script for graphcool
const _ = require('lodash')
const { Lokka } = require('lokka')
const { Transport } = require('lokka-transport-http')
const debug = require('debug')('Transport')
const client = new Lokka({
transport: new Transport('https://api.graph.cool/simple/v1/graphcoolendpoint')
})
@idkjs
idkjs / branch-complete-graphcool.jsx
Created June 15, 2017 15:40
refactored branch method with recompose from Medium Article
import React from 'react';
import { withState, pure, branch, renderComponent, compose } from 'recompose';
import { gql, graphql } from 'react-apollo';
// Define a very basic loading state component - you could make this
// a nice animation or something
const Loading = () => (
<div>Loading</div>
);
import React, { Component } from 'react';
import { graphql } from 'react-apollo';
import { MatchSummary, NoDataSummary } from '@mls-digital/react-components';
import MatchSummaryQuery from './match-summary.graphql';
const mapResultsToProps = ({ data }) => {
if (!data.match)
return {
loading: data.loading,
};
import { get } from 'lodash';
import { withRouter } from 'react-router';
import { graphql } from 'react-apollo';
import { compose, mapProps } from 'recompose';
import jobListQuery from './jobList.graphql';
function SomeBaseComponent() {
{/*... some component...*/}
}
@raine
raine / ramda
Last active May 4, 2020 12:14
Browse Ramda documentation in Terminal
#!/usr/bin/env bash
# Browse Ramda documentation in Terminal
# Requires jq and a tool such as fzf or peco for interactive filtering
LATEST="http://raine.github.io/ramda-json-docs/latest.json"
DOCS_URL="http://ramdajs.com/docs/"
json=$(curl -s $LATEST)
functions=$(echo "$json" | jq -r '.[] | if .sig and (.sig | length > 0) then .name + " :: " + .sig else .name end')