ClojureDart icon indicating copy to clipboard operation
ClojureDart copied to clipboard

interop support of extensions

Open cgrand opened this issue 3 years ago • 3 comments

I'd like to expose extensions as regular functions, I don't like pretending they are member of classes.

cgrand avatar Apr 13 '22 08:04 cgrand

The design issues with extensions support: How to compile (.ext_method not-hinted-value)? Not forgetting too take into account that a class may have a method going by the same name as ext_method...

Possible answers (not necessarily mutually exclusive): 1/ namespaced methods like (.fa/AnimateWidgetExtensions.animate w) (cheap to implement but ugly) 2/ on dynamic call when method name matches a known (= in a required package) extension then add type checks against the extended to the emitted dart code

if (target is Widget) { // there may be multiple matching extensions
  (target as Widget).animate(....)
} else {
  (target as dynamic).animate(....)
}

Solution 2 is the best one as it assumes little knowledge on the user side (don't have to know it's an ext method) and would work even in dynamic calls.

cgrand avatar Feb 04 '23 08:02 cgrand

Closed by accident, because commit message had "should fix #10"

cgrand avatar Feb 19 '23 13:02 cgrand

sorry, did not know that written "should fix" automatically closed a PR...

dupuchba avatar Feb 19 '23 15:02 dupuchba