grammarly / focal

Program user interfaces the FRP way.
Apache License 2.0
723 stars 34 forks source link

Use keyof/lookup types to type Lens.key #11

Closed blacktaxi closed 7 years ago

blacktaxi commented 7 years ago

The property expression approach to create lenses has been very useful, but has always been a hack. The fact that we parse the property expression function's source code with regular expressions at runtime doesn't inspire any confidence just from its description alone. We also had several problems integrating with different instrumentation tools.

This PR implements alternative approach to create lenses and views. It's just as type safe as the property expression way. It also allows you to use the auto-completion feature (only tested in VSCode though).

The rename refactoring unfortunately doesn't work with string keys. Maybe we can find a workaround, or maybe we can decide to live with it. I would like to deprecate the property expression thing at some point, but would only like to do that if it will not significantly worsen the development UX.

Changes in this PR: