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

FieldState Data structure #2

Open
Tracked by #1
DovydasNavickas opened this issue Jan 12, 2020 · 0 comments
Open
Tracked by #1

FieldState Data structure #2

DovydasNavickas opened this issue Jan 12, 2020 · 0 comments
Labels

Comments

@DovydasNavickas
Copy link
Member

Currently, the data structure for the FieldState seems to be finalizing:

interface FieldState<TValue, TData extends {}> {
    readonly id: string;
    readonly name: string;

    readonly data: TData;
    readonly status: FieldStatus;

    readonly fields: Readonly<Dictionary<FieldState<unknown, any>>>;
}

In the previous versions of Forms library, we had FormState and various FieldState derivatives. This complicated things because we couldn't use common mechanisms and had to introduce 2 mechanisms for doing the same operations: one for FormState and one for FieldState.

This time, we arrived to a conclusion that Everything is a field. and that let us simplify the state into a nested structure with only a few properties.

First two properties are basic and identify the Field in a global or local manner:

  • id is a global identifier representing field's place in the state, e.g. person.firstName.
  • name is a local identifier, only representing the field's name it's responsible for, e.g. firstName.

data is where all field specific data will be stored, e.g. a TextField will have currentValue, initialValue, defaultValue, selectionStart, selectionEnd, etc.
data can be different for every field, thus it is like a bag where any field data can be put.

status is represented by FieldStatus interface:

interface FieldStatus {
    focused: boolean;
    touched: boolean;
    pristine: boolean;
    disabled: boolean;
    readonly: boolean;
    permanent: boolean;
}

These statuses represent any field status at a given time. More on them in a separate issue.

And the only one property left here is fields. It is a nested dictionary where all fields are placed and all their data described above can be found.

Some things are still moving around and we are battle-testing this data structure by creating the initial bunch of fields. Looking at the current version of it, I don't thing it will change, as there is not much left to take away 😄

And, as Antoine de Saint-Exupery said:

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.

Thus, we're trying to not add anything into the base structure, unless it proves to be mandatory and we cannot live without it. At least right now there's not much left to take away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant