Skip to content

Instantly share code, notes, and snippets.

@whisher
Created February 17, 2022 22:05
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 whisher/a04adea9cc2c8fb3b7c3c2ca24c1cc3c to your computer and use it in GitHub Desktop.
Save whisher/a04adea9cc2c8fb3b7c3c2ca24c1cc3c to your computer and use it in GitHub Desktop.
export interface DataState {
error: string | null;
loaded: boolean;
data: GetIssuesQuery | undefined;
}
const initialState: DataState = {
error: null,
loaded: false,
data: undefined
};
const store = writable<DataState>(initialState);
const dataStore = {
subscribe: store.subscribe,
success: (data: GetIssuesQuery) => {
store.update((state) => {
return {
...state,
loaded: true,
data
};
});
},
failure: (error:string) => {
store.update(() => {
return {
error,
loaded: false,
data: undefined
};
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment