Skip to content

Instantly share code, notes, and snippets.

👹
Kappa

Jimmy Jia taion

👹
Kappa
Block or report user

Report or block taion

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@taion
taion / registry.js
Last active May 7, 2019
Relay type registry
View registry.js
import decamelize from 'decamelize';
import { fromGlobalId } from 'graphql-relay';
import pluralize from 'pluralize';
import getItem from '../api/getItem';
const types = {};
const endpoints = {};
const getItemOverrides = {};
@taion
taion / async-props-style.js
Last active Jan 24, 2017
React Router data fetching
View async-props-style.js
// Define your components like:
class MyComponent extends React.Component {
static fetchData = (params) => {
// return an action here.
};
/* ... */
}
function fetchComponentData(component, store, params) {
View Post.js
class Post {
static Resource = HttpResource;
static resourceConfig = { endpoint: '/posts' };
@field({ required: true }))
title = 'untitled';
@field()
text = '';
View omit-benchmark.js
const Benchmark = require('benchmark');
const _ = require('lodash');
const props = {
className: 'foo',
onClick: () => null,
children: 'bar',
style: { top: 10 },
relay: {},
intl: {},
@taion
taion / Button.js
Last active Jul 31, 2016
Embarrassing strawman API proposal that hopefully gets the point across
View Button.js
// This is _not_ supposed to be a real API. It's only intended to describe what
// I'm looking for. It's almost intentionally awful.
export const buttonHook = new OverrideHook({
properties: ['margin'],
});
export default function Button(props) {
return (
<button
View Route.js
import invariant from 'invariant';
import React from 'react';
import BaseRoute from 'react-router/lib/Route';
import LoadingIndicator from './LoadingIndicator';
// This is not a component.
/* eslint-disable react/prop-types */
function render({ props, element }) {
if (!props) {
@taion
taion / makeRequired.js
Created Aug 21, 2016
GraphQL CRUD partial updates
View makeRequired.js
/* @flow */
import { GraphQLNonNull } from 'graphql';
export default function makeRequired(partial?: boolean) {
if (partial) {
return (type: mixed) => type;
}
return (type: mixed) => new GraphQLNonNull(type);
@taion
taion / server.js
Last active Aug 16, 2019
GraphQL subscription server with Socket.IO, backed by Redis Pub/Sub
View server.js
const redisClient = redis.createClient(REDIS_URL);
const listeners = Object.create(null);
function addListener(channel, listener) {
if (!listeners[channel]) {
listeners[channel] = [];
redisClient.subscribe(channel);
}
listeners[channel].push(listener);
View runQuery.js
import Relay from 'react-relay';
export default function runQuery(
queryNode,
args,
environment,
forceFetch = false,
) {
const query = Relay.createQuery(queryNode, args);
View NetworkLayer.js
import io from 'socket.io-client';
import RelayNetworkLayer from '@taion/relay-network-layer';
const MAX_SUBSCRIPTIONS = 200;
const EMPTY_SUBSCRIPTION = {
dispose() {},
};
/**
You can’t perform that action at this time.