Thursday, October 19, 2017

Re: cast Element to Elemental2

This is nice, I did not know this.

Would this be the preferred way of getting Elemental2 Context2d from calling getContext("2d")? Because the Elemental2 Context2d does'nt have Element in ancestry...
Or doing it as Brandon did:
CanvasRenderingContext2D
context = (CanvasRenderingContext2D) (Object) canvas.getContext("2d");?
In https://gist.github.com/branflake2267/8e4b9d4f2dc594fe21a125155516ec97

Kind regards,
Max

Am Mittwoch, 18. Oktober 2017 17:35:29 UTC+2 schrieb Colin Alworth:
That can still be done in JsInterop through the Js class - Js.cast does it safely, and Js.uncheckedCast does your JSNI version, but in a way that will continue to work correctly in J2CL.

The class also contains casts to all primitives.

If you are using elemental2, this should already be on your classpath, otherwise you can add it from maven using
 
   <dependency>
     
<groupId>com.google.jsinterop</groupId>
     
<artifactId>base</artifactId>
     
<version>1.0.0-beta-1</version>
   
</dependency>


On Wednesday, October 18, 2017 at 9:34:41 AM UTC-5, Vassilis Virvilis wrote:
Thomas advice is of course preferable

But sometimes gwt type checking drives me crazy. Then I use this

JsUtil.java
----
   public static native <T, V> V cast(T data) /*-{
        return data;
    }-*/;
----

This casts anything to anything...

   Vassilis


On Wed, Oct 18, 2017 at 2:39 PM, Thomas Broyer <t.br...@gmail.com> wrote:
You should be able to cast a JSO to a JsType (native ones only?)
And in this case they indeed represent the same kind of objects so this is safe.

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.



--
Vassilis Virvilis


--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment