Skip to content

Instantly share code, notes, and snippets.

View phpsmarter's full-sized avatar

ReactSmarter phpsmarter

View GitHub Profile
@phpsmarter
phpsmarter / rn-compose-login.js
Created January 16, 2018 09:45 — forked from renso3x/rn-compose-login.js
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';
@phpsmarter
phpsmarter / list.js
Created January 16, 2018 09:53 — forked from pokorson/list.js
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>
@phpsmarter
phpsmarter / import-books.js
Created January 16, 2018 10:20 — forked from idkjs/import-books.js
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')
})
@phpsmarter
phpsmarter / branch-complete-graphcool.jsx
Created January 16, 2018 10:21 — forked from idkjs/branch-complete-graphcool.jsx
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 { 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...*/}
}
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,
};
```
const { Component } = React;
const { mapProps } = Recompose;
const User = ({ name, status }) =>
<div className="User">{ name }—{ status }</div>;
const UserList = ({ users, status }) =>
<div className="UserList">
<h3>{ status } users</h3>
@phpsmarter
phpsmarter / gql-apollo-test.spec.js
Created January 20, 2018 02:27 — forked from shlomitc/gql-apollo-test.spec.js
A working example of graphql and apollo client test
import 'mocha';
import {expect} from 'chai';
import 'isomorphic-fetch';
import ApolloClient from 'apollo-client';
import gql from 'graphql-tag';
import {print} from 'graphql-tag/bundledPrinter';
describe('some test', () => {
it('should pass', () => {
@phpsmarter
phpsmarter / compose-async.js
Created January 23, 2018 19:37 — forked from export-mike/compose-async.js
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) => {
@phpsmarter
phpsmarter / transducer-rxjs-ramda.js
Created January 25, 2018 03:28 — forked from michiel/transducer-rxjs-ramda.js
transducer in es6 with ramda and rxjs
const Rx = require('rx');
const R = require('ramda');
const seq = Rx.Observable.range(1, 10);
const isEven = (x) => x % 2 === 0;
const add1 = (x) => x + 1;
const transducer = R.compose(
R.map(add1),