Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Babel Macro to transform createAction at compile-time #231

Open
avin-kavish opened this issue Apr 15, 2020 · 0 comments
Open

Babel Macro to transform createAction at compile-time #231

avin-kavish opened this issue Apr 15, 2020 · 0 comments

Comments

@avin-kavish
Copy link

avin-kavish commented Apr 15, 2020

Typesafe Actions is an avoidable increase in bundle size. I'm not sure if it's possible but a Babel Macro would allow us to use the library without adding to the bundle size by creating the actions at compile time instead of run-time. It would also increase run-time performance as createAction does not need to be evaluated on each run. A sample transformation would be,

export const foo = createAction('bar/FOO')<string>()

export const foo = payload => ({ type: 'bar/FOO', payload })
export const fooAsync = createAsyncAction(
  'bar/FOO_REQUEST',
  'bar/FOO_SUCCESS',
  'bar/FOO_FAILURE',
)()

export const fooAsync = {
  request: payload => ({ type: 'bar/FOO', payload }),
  sucess: payload => ({ type: 'bar/FOO_SUCCESS', payload }),
  failue: payload => ({ type: 'bar/FOO_FAILURE', payload }) 
}
@avin-kavish avin-kavish changed the title Babel Macro Babel Macro to transform createAction at compile-time Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant