Skip to content

Instantly share code, notes, and snippets.

View dacz's full-sized avatar

David Cizek dacz

View GitHub Profile
@dacz
dacz / gist:60028
Last active April 26, 2017 11:03
happy
unless Life.include?(:happines)
raise WorldMismatchError
end
@dacz
dacz / perf-concat.js
Last active May 27, 2017 10:43
Perf array clone with concat or Array.from
const makeSmallArrays = count => [ ...(new Array(count)) ].map((_, i) => [i, i.toString()]);
// generate arrs
// a lot of small ones
const countSmall = 1000;
arrOfSmalls = makeSmallArrays(countSmall);
// cost of duplicating array
const fnConcat = arr => arr.concat();
@dacz
dacz / validate.js
Last active August 9, 2017 16:24
Form validator
/*
For my use only but happy to explain it to anyone interested:
I'm not into use controlled components everywhere.
Forms collects the values and submit does... well submit.
Because of React twisted events (synthetic) this approach uses:
- every input has a unique name
- then you will get obj vith name: value keys
- you can specify which name should be picked up

Feature: Add customer to PE dashboard

As an PE administrator I'm able to add new user to the PE dashboard and give her access to specific project.

Given:

  • I'm PE administrator and I'm logged in to PE system.
  • I have email address of the customer to be added

Steps:

  1. I select "new user" action
// queries.graphql.js
import gql from 'graphql-tag';
const USER_FRAGMENT = gql`
fragment userFragment on User {
id
username
email
}
// schemaPlain.js
export default `
type Post {
id: ID!
title: String
content: String
author: User
}
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { createBridgeLink } from 'apollo-bridge-link';
import { dataLoadersFactory } from './rest';
import { mergeDeepRight } from 'ramda';
import resolvers from './resolvers';
import schema from './schemaPlain';
import { setContext } from 'apollo-link-context';
const mock = true;
@dacz
dacz / apolloClient.js
Created December 1, 2017 15:07
apollo-bridge-link ... to article on Medium
// apolloClient.js
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory'; // eslint-disable-line import/no-unresolved
import { createBridgeLink } from 'apollo-bridge-link';
import { dataLoadersFactory } from './rest';
import resolvers from './resolvers';
import schema from './schemaPlain';
import { setContext } from 'apollo-link-context';
// resolvers.js
import rest from './rest';
export default {
Query: {
post: (...args) => rest.getPost(...args),
posts: (...args) => rest.getPosts(...args),
user: (...args) => rest.getUser(...args),
users: (...args) => rest.getUsers(...args),
// rest.js
import DataLoader from 'dataloader';
import { REST_URL } from './links';
import fetcher from './fetcher';
// ---- DATA LOADERS
export const dataLoadersFactory = ctx => ({
dataLoaders: {