Skip to content

Instantly share code, notes, and snippets.

@TracyNgot
Created September 20, 2018 23:24
Show Gist options
  • Save TracyNgot/9152ad6a2b01708161f197744bd2f2ab to your computer and use it in GitHub Desktop.
Save TracyNgot/9152ad6a2b01708161f197744bd2f2ab to your computer and use it in GitHub Desktop.
Action example with TypeScript
export default class UnicornActions {
public static Types = {
ERROR: 'UNICORN_ERROR',
GET_UNICORN: 'GET_UNICORN',
LIKE_UNICORN: 'LIKE_UNICORN',
SUCCESS: 'UNICORN_SUCCESS',
UPDATE_UNICORN: 'UPDATE_UNICORN',
}
public static error = (err: any, actionName: string) => ({
actionName,
error: err,
type: UnicornActions.Types.ERROR,
});
public static done = (data: any, actionName: string) => ({
actionName,
response: data,
type: UnicornActions.Types.SUCCESS
});
public static getUnicorn = (id: string) => ({
id,
type: UnicornActions.Types.GET_UNICORN
});
public static likeUnicorn = (id: string) => ({
id,
type: UnicornActions.Types.LIKE_UNICORN
});
public static updateUnicorn = (id: string, data: any) => ({
data,
id,
type: UnicornActions.Types.UPDATE_UNICORN
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment