ClojureDart icon indicating copy to clipboard operation
ClojureDart copied to clipboard

More consistent `:get`

Open valerauko opened this issue 1 year ago • 7 comments

The syntax for widget's :get is wildly different from other forms of binding, which makes it confusing (and harder to lint).

It'd be nice if it could be "just" a regular vector like other bindings (with extra options available like with :managed)

valerauko avatar Sep 14 '23 06:09 valerauko

@valerauko do you have suggestions in mind?

dupuchba avatar Oct 04 '23 12:10 dupuchba

I don't know how to make it non-breaking (apart from finding a new name -- do you have a new name to propose?).

cgrand avatar Oct 04 '23 16:10 cgrand

From the documentation comment of widget, it seems to me that :get does two things:

  • fetch a value from :bind
  • call .of with context on classes

I can't comment on the :bind utility since I've never used :bind (tbh I don't really understand why it exists)

My biggest issue with the :value-of [Navigator Theme] syntax is that it implicitly names bindings and that just feels... wrong?

Maybe having the :value-of option at the top level of widget? (Possibly with another name like below to reduce confusion)

(widget
 :from-ctx [nav m/Navigator
            theme m/Theme]
 ,,,)

valerauko avatar Oct 05 '23 02:10 valerauko

:bind {:app-state app-state :global-cache cache} is just an utility that avoid users to pass the a defined value as function you can :get a binded value which avoid you to create a (defn my-widg [app-state]...)

dupuchba avatar Oct 05 '23 07:10 dupuchba

:bind serves the same purpose as binding in Clojure: it makes "ambiently" available to descendants a value without having to pass this value everywhere as an explicit argument. In practice you could use bind to make a db connection or state or whatever available to descendants without having a global (and thus allowing local redefinition, isolation, testing (wishful thinking in action) etc.) And that's also what Flutter does for ThemeData, Navigator etc. you. That's why they are lumped together under :get because they use the same access pattern.

cgrand avatar Oct 05 '23 07:10 cgrand

just to know (and not talking about the vector): would the magic behind :get [Theme PageStorage] introducing theme and page-storage locals be more tolerable if it worked in reverse? :get [theme page-storage]?

cgrand avatar Oct 05 '23 08:10 cgrand

Not really.

At this point we're "working around" this implicitness by using the explicit {nav m/Navigator} syntax instad.

It just feels really weird to have a map-based binding when everywhere else it's the let-like vector syntax.

valerauko avatar Oct 05 '23 08:10 valerauko