Last active
November 12, 2020 07:12
-
-
Save guillaumewuip/63f6f348dd8d83b369c1d6f992e37ab6 to your computer and use it in GitHub Desktop.
State and Store in frontend codebase - State example - state API
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
export const decode = (apiPayload: unknown): Loaded | Failure => { | |
// parse payload | |
// remove admins | |
// if something goes wrong, return Failure | |
}; | |
export const users = (state: Loaded) => state.users; | |
export const addUser = (user: User.User) => ( | |
state: Loaded | |
): Loaded | Failure => { | |
if (state.users.length >= 10) { | |
return new Error("oops"); | |
} | |
return { | |
...state, | |
users: [...state.users, user] | |
}; | |
}; | |
export const isLoading = (state: State): state is Loading => // ... | |
export const isError = (state: State): state is Failure => // ... | |
export const canCreateUser = (state: State): boolean => //... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment