controls-state icon indicating copy to clipboard operation
controls-state copied to clipboard

API is a bit confusing

Open rreusser opened this issue 5 years ago • 2 comments

The API works, but it's a bit confusing. I'd love to just rename everything (the internal APIs, really) a bit more consistently so that they're a bit easy and more natural to comprehend. I wrote it and I still struggle to remember how to navigate the hierarchy.

rreusser avatar Apr 25 '19 20:04 rreusser

Interesting.. what do you still find confusing nowadays? What the hardest stuff to remember?

marcofugaro avatar Jul 27 '19 10:07 marcofugaro

A lot of the trickiness is contained in this section:

https://github.com/rreusser/controls-state/blob/60011d783d62f69fcc0090f1139ff69df767b772/src/fields/section.js#L85

state is actually "field accessor" object that returns values when you query state.propname rather than the field instance itself. With the exception of section. state.section returns a field accessor object for that section.

The result is this:

  • state.propname: returns a value
  • state.$field.propname: returns the field instance so that you can operate on it
  • state.sectionname: returns a "field accessor" with properties defined so that…
  • state.sectionname.propname: returns a value. but of course what if we want the instance, so that…
  • state.sectionname.$field.propname: will return the field instance

The goal was to make a very simple API for 95% of the use cases, which are just querying values. The downside is that I get a little turned around when navigating the internals.

rreusser avatar Jul 27 '19 17:07 rreusser