esamattis / immer-reducer

Type-safe and terse reducers with Typescript for React Hooks and Redux
http://npm.im/immer-reducer
MIT License
225 stars 15 forks source link

feat: Allow custom action type prefix #13

Closed iamchanii closed 5 years ago

iamchanii commented 5 years ago

Issue: #12

esamattis commented 5 years ago

Thanks! But unfortunately this does not work. I extended your test to actually test action dispatching with the custom prefix.

It fails because createReducerFunction must also known about the custom prefix:

https://github.com/iamchanii/immer-reducer/blob/e25730832b5c8c1d25b8400fe51d95267bc4e805/src/immer-reducer.ts#L205

I wonder if it would be better to just expose a function setPrefix which sets the internal PREFIX. Then there would be no need to manually pass the prefix for all createActions and createReducerFunction calls. It would not be as flexible though (and mutating internals is not that cool).

Usage would be like this:

import {setPrefix} from "immer-reducer";

setPrefix("MY_PREFIX");
iamchanii commented 5 years ago

I see. I'll be done before next weekend. Thanks for your advice and kind!

iamchanii commented 5 years ago

I fixed! I'd be glad to you review my code.

FYI: I changed prefix variable name to actionTypeName from PREFIX. because, I think it is not anymore constraint variable if this PR approved.

esamattis commented 5 years ago

Thanks! Available now in 0.3.0 🚀