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

resolve #111: allow passing initial state to curried producer function #121

Merged
merged 1 commit into from Mar 17, 2018
Merged

resolve #111: allow passing initial state to curried producer function #121

merged 1 commit into from Mar 17, 2018

Conversation

pkerschbaum
Copy link
Contributor

Should implement issue #111.

Notes:

  • If a function is given both for fn and initialState, produce(fn, initialState) will throw an error, see https://github.com/pkerschbaum/immer/blob/202d54cb96949b45cdfdfb08f180b93723faef29/src/immer.js#L24.
    Because if produce would allow this, each call of the curried function with undefined would create a curried function again.
  • The typings should be improved because currently, S is typed with any, and if two arguments are passed to produce, TypeScript (and I think also Flow) cannot exactly determine which overloaded version of the function gets called.
    If we add typings for the state/currentState/initialState S, the typing systems should be able to distinguish the produce calls.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.08%) to 96.296% when pulling 202d54c on pkerschbaum:feature/initial-state-for-curry-fn into 77c17f7 on mweststrate:master.

@Anmo
Copy link

Anmo commented Mar 16, 2018

Hi, I'm starting to test Immer (nice work @mweststrate 👍).

First, thanks @pkerschbaum for this PR.

But, regarding this issue, could I just give my feedback?
I would prefer to have a different method, instead of changing produce (even worse, when the original one already receive 2 parameters).

I would do something like (not necessary this method name 😛): produceWithInitialState(initialState, producer).

What you guys think about?

@mweststrate
Copy link
Collaborator

Great! Thanks a lot

@mweststrate mweststrate merged commit 2cb5496 into immerjs:master Mar 17, 2018
mweststrate added a commit that referenced this pull request Mar 22, 2018
…rry-fn

resolve #111: allow passing initial state to curried producer function
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

Successfully merging this pull request may close these issues.

None yet

4 participants