-
-
Save OliverJAsh/86ed88d55204a87818241d52837986a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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