Skip to content

Instantly share code, notes, and snippets.

@cgrand
Last active June 24, 2021 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgrand/9c64f6854a84fbad78b4012eacc057b0 to your computer and use it in GitHub Desktop.
Save cgrand/9c64f6854a84fbad78b4012eacc057b0 to your computer and use it in GitHub Desktop.
super in ClojureDart

Accessing super members in ClojureDart

In ClojureDart deftype (and reify) can extend abstract classes and, as a consequence, we need a way to call super implementations (even on fields because of getters/setters).

For example, this Dart

class WebViewExampleState extends State<WebViewExample> {
  @override
  void initState() {
    super.initState();
    if (Platform.isAndroid) WebView.platform = SurfaceAndroidWebView();
  }
  ...
}

can be translated to this ClojureDart:

(deftype WebViewExampleState
  :extends #/(State WebViewExample)
  (initState [^{:super daddy} self]
    (.initState daddy)
    (when Platform/isAndroid (set! WebView/platform (SurfaceAndroidWebView.)))
  ...)

So the :super metadata on the this parameter of a method allows to introduce a name for super.

Super calls can even occur in closures (fns or reifies) they'll act on the right instance, not on the super of the closure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment