Add CanvasRenderingContext2D to `ceylon.interop.browser`
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?
Interested in this @bjansen ? :)
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.
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?
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.
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.
Moving to 1.2.3