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

Record value of a field #69

Open
alex35mil opened this issue Mar 21, 2020 · 1 comment
Open

Record value of a field #69

alex35mil opened this issue Mar 21, 2020 · 1 comment

Comments

@alex35mil
Copy link
Member

There are 2 possible use-cases for record value. Both can use [@field.entity] attribute.

  1. Deserialization of set of fields into single type:
type input = {
  date: [@field.entity] date',
}
and date' = {
  day: int,
  month: int,
  year: int,
};

type output = {date: Js.Date.t};

type validators = {
  date: {
    entity: date' => result(Js.Date.t, message),
    fields: {
      day: {
        strategy: Strategy.t,
        validate: input => result(int, message),
      },
      ...
    }
  }
};

// Interface
form.updateDateYear(2020)
form.dateYearResult
form.dateResult
  1. Scoping set of fields. It might be useful when there is select in the form which affects which set of fields would be shown to a user.
type input = {
  select,
  a: [@field.entity] a',
  b: [@field.entity] b',
}
and select = A | B,
and a' = { fieldA: string }
and b' = { fieldB: string };

type output = {
  select,
  a: a',
  b: b',
};

I'm not sure if the second one is useful though since it's possible to implement it using current api. But if it is, then the question is how to name each.

Also, the prototype of the former is not really thought out so suggestions are welcome.

@alex35mil
Copy link
Member Author

As an option:

[@field.entity {output: Abstract}] // #1: deserialization into single type
[@field.entity {output: Record}] // #2: fields scoping

Not sure about Abstract & Record naming, prolly ok.

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

No branches or pull requests

1 participant