Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Migrate to Halogen Hooks version #66

Open
JordanMartinez opened this issue Apr 6, 2020 · 2 comments
Open

Migrate to Halogen Hooks version #66

JordanMartinez opened this issue Apr 6, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@JordanMartinez
Copy link

... and potentially fix #61, #62, and #64 along the way.

I think the hook version of this library could be broken up into two parts: various hooks for fields and a hook for the form itself

A field hook would have the following things:

I'm not sure what a form hook would have as I can't recall all the things this library provides.

@JordanMartinez
Copy link
Author

So, here's a problem.

A given field has the following pieces of state:

  • input
  • touched
  • output (i.e. the value when successfully validated)
  • dirty

If I want to render a dynamically-sized array of fields, I would idealy write something like this:

allFields <- for arrayOfItems \item -> useField item

However, for/traverse and indexed monads don't play well together.

So, the only workaround I can think of is to create a variant of useField that does something like this:

useManyFields array = Hooks.do
  inputs /\ tInputs <- useState (map (_.input) array)
  toucheds /\ tToucheds <- useState (map (\_ -> false) array)
  valids /\ tValids <- useState (map (\_ -> NotValidated) array)
  dirtys /\ tDirtys <- useState (map (\_ -> false) array)

Getting. setting, or modifying the corresponding value in the corresponding array will require using lenses to prevent verbosity

@thomashoneyman thomashoneyman self-assigned this Apr 8, 2020
@thomashoneyman thomashoneyman added the enhancement New feature or request label Apr 8, 2020
@thomashoneyman thomashoneyman added this to the Halogen 5 milestone Apr 8, 2020
@thomashoneyman
Copy link
Owner

While I am open to a Hooks version of Formless, I'm not currently planning to work on this. I did implement a working Hooks version of Formless, but I never felt satisfied with its ergonomics. You can see that work here:

https://github.com/thomashoneyman/purescript-halogen-formless/tree/hooks

In addition, others have updated that code for 0.14:

#71
#72

If someone would like to continue on this direction, please do! But I am not personally planning to work on it.

@thomashoneyman thomashoneyman removed this from the Halogen 5 milestone Mar 3, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants