Skip to content

Instantly share code, notes, and snippets.

View phpsmarter's full-sized avatar

ReactSmarter phpsmarter

View GitHub Profile
@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>
);
@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 / 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 / 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 / sample_code1.js
Created January 16, 2018 09:10 — forked from char0n/sample_code1.js
Composing lenses in Ramda
import { lensPath, view } from 'ramda';
const complexObject = { level1: { level2: { prop1: 1, prop2: 2 } } };
const prop1Lens = lensPath(['level1', 'level2', 'prop1']);
console.assert(view(prop1Lens, complexObject) === 1);
@phpsmarter
phpsmarter / ramdaprogram.js
Created January 16, 2018 09:08 — forked from 1Marc/ramdaprogram.js
ramda program
var byMonth = R.groupBy(R.prop('Month'));
var byAuthor = R.groupBy(R.prop('Author'));
var royalty_key = 'Royalty (SUM)';
var months_keys = R.uniq(R.map(R.prop('Month'), data)).sort();
var monthly_revenue =
R.map((group) =>
R.reduce((acc, record) => acc + parseMoney(record[royalty_key]), 0, group),
byMonth(data));
@phpsmarter
phpsmarter / scratch.js
Created January 16, 2018 09:07 — forked from walkermatt/scratch.js
Ramda stuff
var R = require('ramda');
var states = [
{symbol: 'CT', name: 'Connecticut', pop: 3574097},
{symbol: 'ME', name: 'Maine', pop: 1328361},
{symbol: 'MA', name: 'Massachusetts', pop: 6547629},
{symbol: 'NH', name: 'New Hampshire', pop: 1316470},
{symbol: 'RI', name: 'Rhode Island', pop: 1052567},
{symbol: 'VT', name: 'Vermont', pop: 623741},
];
@phpsmarter
phpsmarter / deep-merge.js
Created January 16, 2018 09:04 — forked from mrtnbroder/deep-merge.js
Ramda Receips
import R from 'ramda'
const mergePlan = (x, y) => {
if(Array.isArray(x) && Array.isArray(y)) {
return R.uniq(R.concat(x, y));
}
if(typeof x === 'object' && typeof y === 'object'){
return R.mergeWith(mergePlan, x, y)
}
@phpsmarter
phpsmarter / code02.js
Last active January 16, 2018 08:47 — forked from BnayaZil/code02.js
Ramda series
import {prop, compose, apply, defaultTo, juxt} from 'ramda'
const player = {
id: 1,
name: 'Bnaya',
file: {
img: 'http://foo.bar/bnaya-zil.png'
}
}
'use strict';
var R = require('ramda');
var CATEGORIES = [
{category_type: 'cuisine', id: 1, name: 'French', type: 'categroy'},
{category_type: 'diets', id: 2, name: 'Vegetarian', type: 'category'}
];
var children = {