Skip to content

Instantly share code, notes, and snippets.

@koba04
Created June 6, 2019 04:33
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 koba04/78dad5c6b755a795240cba21d680f256 to your computer and use it in GitHub Desktop.
Save koba04/78dad5c6b755a795240cba21d680f256 to your computer and use it in GitHub Desktop.
import { Dispatch } from 'redux'
export type Dispatch = Dispatch
export const createUseCase = <T>(name: string, usecase: () => Promise<any>) => async () => {
if (process.env.NODE_ENV === 'development') {
console.groupCollapsed(`%c[UseCase]%c ${name}`, 'color: #00c4cc', '')
console.time(name)
performance.mark(`start:${name}`)
}
await usecase()
if (process.env.NODE_ENV === 'development') {
console.timeEnd(name)
console.groupEnd()
performance.mark(`end:${name}`)
performance.measure(`[UseCase] ${name}`, `start:${name}`, `end:${name}`)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment