Hi, Basarat, great work as usual 😉 Already using it in my project. I have one question though about array. How do you specify a field that contains an array of complex objects. In your docs you have two form states, is that necessary?
TL;DR;
So, can a FieldState
contain an array of FormStates
as its value?
Example:
class A {
a: number;
b: string;
}
class B = {
arr: A[]
}
can I model it like this?
// i like to have all types globally available in order to reduce imports, don't judge ;)
declare global {
namespace App.Models {
type AStateFields = {
a: FieldState<number>;
b: FieldState<string>;
}
type BStateFields = {
arr: FieldState<AStateModel[]>;
}
type AState = AStateModel;
type BState = BStateModel;
}
}
class AStateModel extends FormState<App.Models.AStateFields> {
constructor(a: A) {
super({
a: new FieldState(a.a),
b: new FieldState(a.b),
})
}
}
class BStateModel extends FormState<App.Models.BStateFields> {
constructor(b: B) {
super({
arr: new FieldState(b.map(item => new AStateModel(item)))
})
}
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:11
Top Results From Across the Web
What is Array? - GeeksforGeeks
An array is a collection of items of same data type stored at contiguous memory locations. This makes it easier to calculate the...
Read more >Arrays (Java Platform SE 7 ) - Oracle Help Center
Searches a range of the specified array for the specified object using the binary search algorithm. static <T> int, binarySearch(T[] a, T key,...
Read more >Array - JavaScript - MDN Web Docs
The Array object, as with arrays in other programming languages, enables storing a collection of multiple items under a single variable name ...
Read more >Array - Wikipedia
An array is a systematic arrangement of similar objects, usually in rows and columns. The little push-buttons on the upper part of the...
Read more >Java Arrays - W3Schools
Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value. To declare an array,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
G’day mate 😃! I saw your tweet and checked out the tutorial and was very happy with it! Thanks for the amazing work you are doing. Your effort is cutting down the development and refactoring time immensely and is just pleasure to work with it.
@tomitrescak So the way we’ve been handling this is by maintaining additional validation rules regarding the overall form state in our State classes.
But to make it easier to just use formstate just pushed a new version
0.10.0
that allows you to add validators toFormState
. This works nice with your example. Also you don’t need to make arrays observable sinceFormState.$
is automatically made observable for you. Simplified yourCars
/Features
example further and used it as a tutorial here : https://formstate.github.io/demos/#formstate Hope you like it 🌹 ❤️