formstate
formstate copied to clipboard
Add getRawValues functionality
As discussed in https://github.com/formstate/formstate/issues/69, this PR adds a function in formState
and fieldState
classes to get their raw, unobserved values. The function implementation uses any
, but the external API is entirely type-safe.
@basarat, if you approve of the functionality, I'll add tests and documentation.
I've refactored validate
method to return unwrapped values. This simplifies the logic from:
const res = await form.validate();
if (res.hasError) return;
/** {username: string, password: string} */
const somethingToSendToServer = form.$.map(child =>
({username: child.$.username.$, password: child.$.password.$})
);
to something like this:
const res = await form.validate();
if (res.hasError) return;
/** {username: string, password: string} */
const somethingToSendToServer = res.value;
As you can see, no mapping or unwrapping is required. This is type-safe as before.
Thanks @ivasilov I really appreciate the effort you have put in this :rose: ❤️
However I won't be able to merge this (or any other features) for the forseeable future. Some context:
- This project is one of the last projects (others being typestyle - someone else is maintaining, takeme - loved by some - agnostic by other) still heavily used by my org - means it has to stay frozen
- Teams beyond my influence are experimenting with alternatives - mostly mobx free - of which there are many - to many for me to discuss comparisons
- My org no longer sponsors me to work on open source during work hours - I have plenty of ideas that need working on in formstate, but I need to park it if its not appreciated.
Sorry about that. But the code in formstate is not locked in so you can either:
- fork
- create
class Additional extends FieldState
.
Sorry that neither of options are ideal 🙇♀ I will leave this PR open as your code is quality.
@basarat would you consider adding me to the organization? I can start working on a 2.0 version of formstate
(because of the breaking changes) which will also solve the "has to stay frozen" issue.
I'm also planning on adding reset(value?: TValue)
functionality to formState
.
We're using it heavily in our organization and it's a perfect fit for our mobx-oriented usage.
We're using it heavily in our organization and it's a perfect fit for our mobx-oriented usage.
@ivasilov We run into similar situation with yours. That's why we built another formstate with some extra features, such as get raw values (actually we refactored it totally to leverage MobX's power substantially). If possible, we can build it together:)
And here is the project.