Skip to content

Instantly share code, notes, and snippets.

@rodrigopr
Last active September 28, 2016 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigopr/c0111e9dacdb2351854ea8b420676cb8 to your computer and use it in GitHub Desktop.
Save rodrigopr/c0111e9dacdb2351854ea8b420676cb8 to your computer and use it in GitHub Desktop.
// @flow
/* eslint-disable jsx-control-statements/jsx-jcs-no-undef, no-unused-vars */
import React from 'react';
import Relay from 'react-relay';
/*
* Type mapping:
* D - DefaultProps
* P - Props
* S - State
* F - FragmentConfig
* V - VariablesConfig
*/
type $Record<T> = {[key: $Keys<T>]: any};
type StatelessComponent<P> = (props: P) => ?React$Element<any>;
type ContainerOptions<F, V> = {
fragments: F,
initialVariables?: V,
prepareVariables?: (prevArgs: $Record<V>) => $Record<V>
}
type PropsWithoutRelay<P> = $Diff<{ relay: RelayInstance<*> }, P>;
declare class RelayContainer<D, P, F, V> extends React$Component<D, P, void> {
static getFragment(
fragmentName: $Keys<F>,
variableMapping?: $Shape<V>
): any;
}
type createContainerDef = <D, P, S, F, V>(
BaseComponent: StatelessComponent<D> | Class<React$Component<D, P, S>>,
options: ContainerOptions<F, V>
) => Class<RelayContainer<D, PropsWithoutRelay<P>, F, V>>;
export type RelayInstance<V> = {
setVariable(params: $Shape<V>): void
}
export const createRelayContainer: createContainerDef = Relay.createContainer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment