rreusser / controls-state

⚙️ An object for managing state
https://observablehq.com/@rreusser/control-panel-2-prototype-test
21 stars 2 forks source link

API is a bit confusing #1

Open rreusser opened 5 years ago

rreusser commented 5 years ago

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.

marcofugaro commented 5 years ago

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

rreusser commented 5 years ago

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:

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.