Skip to content

Instantly share code, notes, and snippets.

@OliverJAsh
Created September 10, 2018 16:44
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 OliverJAsh/86ed88d55204a87818241d52837986a5 to your computer and use it in GitHub Desktop.
Save OliverJAsh/86ed88d55204a87818241d52837986a5 to your computer and use it in GitHub Desktop.
// states.ts
import { GalleryItem } from './types';
export enum StateType {
Form = 'Form',
Loading = 'Loading',
Failed = 'Failed',
Gallery = 'Gallery',
}
type Form = { type: StateType.Form };
export const form = (): Form => ({ type: StateType.Form });
type Loading = { type: StateType.Loading; query: string };
export const loading = ({ query }: { query: string }): Loading => ({
type: StateType.Loading,
query,
});
type Failed = { type: StateType.Failed };
export const failed = (): Failed => ({ type: StateType.Failed });
type Gallery = { type: StateType.Gallery; items: GalleryItem[] };
export const gallery = ({ items }: { items: GalleryItem[] }): Gallery => ({
type: StateType.Gallery,
items,
});
export type State = Form | Loading | Failed | Gallery;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment