22
33import com .google .gwt .core .client .GWT ;
44import com .google .gwt .core .client .JavaScriptObject ;
5- import com . google . gwt . core .client . JsArray ;
5+ import elemental2 . core .Array ;
66import com .google .gwt .dom .client .Document ;
77import com .google .gwt .dom .client .Element ;
88import com .google .gwt .user .client .DOM ;
9- import com .google .gwt .user .client .Timer ;
109
11- import com .vaadin .polymer .elemental . Function ;
12- import com . vaadin . polymer . elemental .HTMLElement ;
10+ import com .vaadin .polymer .PolymerFunction ;
11+ import elemental2 . dom .HTMLElement ;
1312
1413import java .util .ArrayList ;
1514import java .util .HashMap ;
2221import jsinterop .annotations .JsPackage ;
2322import jsinterop .annotations .JsProperty ;
2423import jsinterop .annotations .JsType ;
24+ import jsinterop .base .Js ;
2525
2626@ SuppressWarnings ({"rawtypes" , "unchecked" })
2727public abstract class Polymer {
@@ -61,11 +61,11 @@ public interface DomApi {
6161
6262 <T extends HTMLElement > T querySelector (String selector );
6363
64- JsArray querySelectorAll (String selector );
64+ Array querySelectorAll (String selector );
6565
6666 void appendChild (Object el );
6767
68- JsArray children ();
68+ Array children ();
6969 }
7070
7171 @ JsType (isNative =true , namespace =GLOBAL )
@@ -120,7 +120,7 @@ public interface Base {
120120 * timing (after the current method finishes, but before the next event from the event
121121 * queue is processed). Returns a handle that can be used to cancel the task.
122122 */
123- Object async (Function method , int wait );
123+ Object async (PolymerFunction method , int wait );
124124
125125 /**
126126 * Cancels the identified async task.
@@ -143,7 +143,7 @@ public interface Base {
143143 /**
144144 * Dynamically imports an HTML document.
145145 */
146- void importHref (String href , Function onload , Function onerror );
146+ void importHref (String href , PolymerFunction onload , PolymerFunction onerror );
147147
148148 /**
149149 * Takes a URL relative to the <dom-module> of an imported Polymer element, and returns
@@ -154,7 +154,7 @@ public interface Base {
154154 }
155155
156156 private static Set <String > urlImported = new HashSet <>();
157- private static HashMap <String , List <Function >> whenImported = new HashMap <>();
157+ private static HashMap <String , List <PolymerFunction >> whenImported = new HashMap <>();
158158
159159 /**
160160 * Inserts the appropriate <import> of a component given by url.
@@ -171,7 +171,7 @@ public static void importHref(String href) {
171171 * @param href either an absolute url or a path relative to bower_components folder.
172172 * @param ok callback to run in case of success
173173 */
174- public static void importHref (String href , Function ok ) {
174+ public static void importHref (String href , PolymerFunction ok ) {
175175 importHref (href , ok , null );
176176 }
177177
@@ -191,7 +191,7 @@ private static String absoluteHref(String hrefOrTag) {
191191 }
192192
193193 // Loads Polymer once if not done yet, and queue all callbaks until ready
194- private static native void whenPolymerLoaded (Function ok )
194+ private static native void whenPolymerLoaded (PolymerFunction ok )
195195 /*-{
196196 function resolve() {
197197 // Set our static reference to Base
@@ -236,19 +236,19 @@ function resolve() {
236236 * @param ok callback to run in case of success
237237 * @param err callback to run in case of failure
238238 */
239- public static void importHref (String hrefOrTag , final Function ok , final Function err ) {
239+ public static void importHref (String hrefOrTag , final PolymerFunction ok , final PolymerFunction err ) {
240240 final String href = absoluteHref (hrefOrTag );
241241
242- Function done = arg -> {
243- urlImported .add (href );
244- List <Function > pending = whenImported .get (href );
245- if (pending != null ) {
246- for (Function f : pending ) {
247- f .call (null );
248- }
242+ PolymerFunction done = arg -> {
243+ urlImported .add (href );
244+ List <PolymerFunction > pending = whenImported .get (href );
245+ if (pending != null ) {
246+ for (PolymerFunction f : pending ) {
247+ f .call (null );
249248 }
250- whenImported .remove (href );
251- return null ;
249+ }
250+ whenImported .remove (href );
251+ return null ;
252252 };
253253 if (Base == null ) {
254254 whenPolymerLoaded (arg -> {
@@ -259,9 +259,9 @@ public static void importHref(String hrefOrTag, final Function ok, final Functio
259259 }
260260 if (!urlImported .contains (href )) {
261261 if (!isRegistered (href )) {
262- List <Function > pending = whenImported .get (href );
262+ List <PolymerFunction > pending = whenImported .get (href );
263263 if (pending == null ) {
264- pending = new ArrayList <Function >();
264+ pending = new ArrayList <PolymerFunction >();
265265 whenImported .put (href , pending );
266266 Base .importHref (href , done , err );
267267 }
@@ -291,9 +291,8 @@ public static void importHref(final List<String> hrefs) {
291291 *
292292 * @param hrefs a list of absolute urls or relative paths to load.
293293 * @param ok callback to run in case of all import success
294- * @param err callback to run in case of failure
295294 */
296- public static void importHref (final List <String > hrefs , final Function ok ) {
295+ public static void importHref (final List <String > hrefs , final PolymerFunction ok ) {
297296 importHref (hrefs , ok , null );
298297 }
299298
@@ -304,8 +303,8 @@ public static void importHref(final List<String> hrefs, final Function ok) {
304303 * @param ok callback to run in case of all import success
305304 * @param err callback to run in case of failure
306305 */
307- public static void importHref (final List <String > hrefs , final Function ok , Function err ) {
308- Function allOk = ok == null ? ok : new Function () {
306+ public static void importHref (final List <String > hrefs , final PolymerFunction ok , PolymerFunction err ) {
307+ PolymerFunction allOk = ok == null ? ok : new PolymerFunction () {
309308 int count = hrefs .size ();
310309 public Object call (Object arg ) {
311310 if (--count == 0 ) {
@@ -355,8 +354,8 @@ public static <T> T createElement(String tagName) {
355354 /**
356355 * Returns the JsInterop instance of Document
357356 */
358- public static com . vaadin . polymer . elemental .Document getDocument () {
359- return ( com . vaadin . polymer . elemental . Document ) Document .get ();
357+ public static elemental2 . dom .Document getDocument () {
358+ return Js . cast ( Document .get () );
360359 }
361360
362361 /**
@@ -376,11 +375,11 @@ private native static boolean isRegisteredElement(Object e)
376375 return !!e && e.constructor !== $wnd.HTMLElement && e.constructor != $wnd.HTMLUnknownElement;
377376 }-*/ ;
378377
379- public static void ready (HTMLElement e , Function f ) {
380- whenReady (f , ( Element ) e );
378+ public static void ready (HTMLElement e , PolymerFunction f ) {
379+ whenReady (f , Js . cast ( e ) );
381380 }
382381
383- public static void ready (Element e , Function f ) {
382+ public static void ready (Element e , PolymerFunction f ) {
384383 whenReady (f , e );
385384 }
386385
@@ -394,7 +393,7 @@ public static void updateStyles() {
394393 /**
395394 * Executes a function after all imports have been loaded.
396395 */
397- public static void whenReady (Function f ) {
396+ public static void whenReady (PolymerFunction f ) {
398397 whenReady (f , null );
399398 }
400399
@@ -408,7 +407,7 @@ private native static boolean htmlImportsSupported()
408407 * passed element is ready to use.
409408 * For browsers not supporting html imports, it loads the webcomponentsjs polyfill.
410409 */
411- public static native void whenReady (Function f , Element e )
410+ public static native void whenReady (PolymerFunction f , Element e )
412411 /*-{
413412 function registered() {
414413 if (e) {
@@ -445,12 +444,12 @@ function loadPolyfill() {
445444
446445 /**
447446 * If an element is not ready, loops until it gets ready, then
448- * run a Function (JsFunction or JavaFunction)
447+ * run a PolymerFunction (JsFunction or JavaFunction)
449448 * @deprecated use {@link #whenReady(Function, Element)} instead.
450449 */
451450 @ Deprecated
452451 private static void onReady (Element e , Object f ) {
453- whenReady ((Function )f , e );
452+ whenReady ((PolymerFunction )f , e );
454453 }
455454
456455 /**
@@ -478,12 +477,12 @@ public static void endLoading(final Element container, Element webcomponent) {
478477 *
479478 * @param container : The container to show when the component is available
480479 * @param webcomponent : Web component to monitor
481- * @param callback : Calback function
480+ * @param func : Calback function
482481 */
483- public static void endLoading (final Element container , Element webcomponent , final Function func ) {
482+ public static void endLoading (final Element container , Element webcomponent , final PolymerFunction func ) {
484483 container .getStyle ().setOpacity (0 );
485484 container .getStyle ().setProperty ("transition" , "opacity 1.1s" );
486- ready (webcomponent , new Function () {
485+ ready (webcomponent , new PolymerFunction () {
487486 public Object call (Object arg ) {
488487 reFlow ();
489488 container .getStyle ().setOpacity (1 );
@@ -531,7 +530,7 @@ public static native <T> List<T> asList(JavaScriptObject o)
531530 * penalty because we directly take the native array of the super ArrayList
532531 * implementation.
533532 */
534- public static native <T extends JavaScriptObject > JsArray <T > asJsArray (List <?> l )
533+ public static native <T extends JavaScriptObject > Array <T > asJsArray (List <?> l )
535534 /*-{
536535 return l.@java.util.ArrayList::array;
537536 }-*/ ;
@@ -570,7 +569,7 @@ public native static void property(Object jso, String name, Object value)
570569 * Utility method for setting a function to a JS object.
571570 * Useful for binding functions to templates.
572571 */
573- public static void function (Object jso , String name , Function fnc ) {
572+ public static void function (Object jso , String name , PolymerFunction fnc ) {
574573 property (jso , name , fnc );
575574 }
576575
@@ -582,16 +581,10 @@ public native static <T> T apply(Object jso, String methodName, Object... args)
582581 return jso[methodName].apply(jso, args);
583582 }-*/ ;
584583
585- public static native <T > T cast (Object o )
586- /*-{
587- return o;
588- }-*/ ;
589-
590584 /**
591585 * Return the dom API of one element.
592586 */
593587 public static DomApi dom (Object element ) {
594588 return Polymer .dom (element );
595589 }
596590}
597-
0 commit comments