Tensegritics / ClojureDart

Clojure dialect for Flutter and Dart
1.44k stars 91 forks source link

More consistent `:get` #268

Open valerauko opened 1 year ago

valerauko commented 1 year ago

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)

dupuchba commented 1 year ago

@valerauko do you have suggestions in mind?

cgrand commented 1 year ago

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

valerauko commented 1 year ago

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

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]
 ,,,)
dupuchba commented 1 year ago

: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]...)

cgrand commented 1 year ago

: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 commented 1 year ago

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]?

valerauko commented 1 year ago

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.