Skip to content

Instantly share code, notes, and snippets.

@brianlovin
brianlovin / index.js
Last active October 29, 2019 20:04
Flow type function prop
// component
type AnotherType = {
data: {
id: string
}
}
type Props = {
aFunction: ({ id: string }) => AnotherType
}
@brianlovin
brianlovin / client.js
Last active January 22, 2018 00:33
Type checking client-side GraphQL with Apollo
// @flow
import * as React from 'react';
import compose from 'recompose/compose';
import getThreadById from './queries'
import type { GetThreadType } from './queries';
type Props = {
data: {
thread: GetThreadType,
...
@brianlovin
brianlovin / test.js
Last active December 18, 2017 21:02
Flow type check
// @flow
import * as React from 'react';
type Props = {
...
}
class Foo extends React.Component<Props> {
render() {
return (
@brianlovin
brianlovin / demo.js
Last active November 9, 2017 03:27
Flow weirdness
// FILE ONE
type Return = {
content: {
body?: string,
title: string,
}
}
const getThread = (id: string): Return => {
// database.get() returns a promise
@brianlovin
brianlovin / query.js
Created November 6, 2017 18:55
Apollo query
import React, { Component } from 'react'
import compose from 'recompose/compose'
import { gql, graphql } from 'react-apollo'
import List from './List'
class Images extends Component {
render () {
const { loading, error, allGalleries } = this.props.allImages
if (allGalleries && allGalleries.length > 0) {
@brianlovin
brianlovin / resolvers.js
Created September 12, 2017 17:07
Resolving downstream info
/*
On Spectrum we store permissions within communities in a table called `usersCommunities`.
This table returns records that look like:
{
id: ID
userId: ID
communityId: ID
isMember: Boolean
isModerator: Boolean
isOwner: Boolean
@brianlovin
brianlovin / demo.js
Created June 20, 2017 22:09
Set State
import React, { Component } from 'react'
export default class Test extends Component {
// if you're using flow or any sort of type checker, you can declar proptypes up here
state: {
value: string
}
// "The constructor method is a special method for creating and initializing an object created with a class." - MDN
constructor() {
@brianlovin
brianlovin / tooltips.js
Last active June 20, 2017 16:09
Tooltips
const returnTooltip = props => {
switch (props.tipLocation) {
case 'top-left':
return `
&:after {
bottom: calc(100% + 5px);
right: 0;
}
&:before {
right: calc(50% - 5px);
@brianlovin
brianlovin / frequency.js
Last active May 1, 2017 18:36
Trying to abstract graphQL fragments
import { gql } from 'react-apollo';
import { userFragments } from './user'
export const frequencyFragments = {
frequencySubscribers: gql`
fragment frequencySubscribers on Frequency {
subscriberConnection {
pageInfo {
hasNextPage
hasPreviousPage
@brianlovin
brianlovin / index.js
Created January 20, 2017 06:43
Routes
var app = require('../app');
var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var async = require('async');
var jwt = require('jsonwebtoken');
var User = require("../models/user.js");
/*------------------------------------------------------------\*
*