bcherny / undux

⚡️ Dead simple state for React. Now with Hooks support.
https://undux.org
MIT License
1.49k stars 31 forks source link

Is it possible to update partial values? #22

Open mironal opened 6 years ago

mironal commented 6 years ago

Hi! Thank you for a wonderfully simple and type-safe library. 😄

I thought about this kind of things. Currently, it seems that I can not set without passing all the properties to set, but I'd like to update the value for partially.

For example, I would like to write the following code.

interface Some {
    one: string
    two: string
}

interface AppStore {
     some: Some
     other: string
}

store.set("some")({one: "hoge"}) // <- Is this possible? Do you have plans to make it possible if you can not? 
bcherny commented 6 years ago

Hey @mironal! No plans to do this yet, but let’s keep this issue open in case there’s demand for it.

You might also consider using a spread as simple syntactic sugar to do this, or something like ImmutableJS to help do these deep updates.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax

https://facebook.github.io/immutable-js/

mironal commented 6 years ago

OK! Thanks for your very quick response!