ceylon-sdk icon indicating copy to clipboard operation
ceylon-sdk copied to clipboard

Add CanvasRenderingContext2D to `ceylon.interop.browser`

Open quintesse opened this issue 9 years ago • 6 comments

See the start @gavinking made with it: https://github.com/ceylon/openshift-cartridge/blob/master/template/source/com/redhat/demo/graph/context.ceylon

Maybe there are other interesting APIs as well?

quintesse avatar Feb 11 '16 16:02 quintesse

Interested in this @bjansen ? :)

quintesse avatar Feb 11 '16 16:02 quintesse

Can we do this kind of check in a JS module?

if (is CanvasRenderingContext2D canvas = document.getElementById("myCanvas"))

IIRC there were problems with dressed objets, that would cause problems to retrieve an instance of this class.

bjansen avatar Feb 11 '16 20:02 bjansen

Well it works if that's what you ask? I know there were problems with dressed objects but that was for very specific frameworks, wasn't it?

quintesse avatar Feb 11 '16 20:02 quintesse

Well I thought when a dynamic interface returns an Element, the instance is dressed as such, so we can't check if it's a subtype of Element, but perhaps I'm wrong.

bjansen avatar Feb 11 '16 20:02 bjansen

This is pretty much where I got stuck when trying to write dynamic interfaces for JS. The return of getContext() depends on the argument.

One idea I tried was to use generics to allow the caller to inform the method of its expected return type:

shared dynamic RenderingContext
        of WebGLRenderingContext | CanvasRenderingContext2D {}

shared dynamic Canvas satisfies Element {
    ...
    shared formal Context getContext<Context>(String contextId)
            given Context satisfies RenderingContext;
}

After a quick google search just now, it looks like this is somewhat similar to an approach used by typescript: http://stackoverflow.com/a/32116589/5076

Disclaimer: I don't know anything about typescript.

jvasileff avatar Feb 11 '16 20:02 jvasileff

Moving to 1.2.3

quintesse avatar Mar 07 '16 17:03 quintesse