elemental2 | Type checked access to browser APIs for Java code | SDK library
kandi X-RAY | elemental2 Summary
kandi X-RAY | elemental2 Summary
Elemental2 provides type checked access to all browser APIs for Java code. This is done by using closure extern files and generating JsTypes, which are part of the new JsInterop specification that is both implemented in GWT and J2CL.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- On load
- Install the UI UI
- Write a message to the page
- Get resolved value
- Add Java types to the given program
- Add as array helper methods
- Clean common array methods
- Helper function to improve the concat method
- Called when the form is submitted
- Add a result
- Clears the results
- Remove all event listeners from the given program
- Checks if the given type implements EventTarget or EventTarget
- Cleans event listener method
- Find the type of a callback parameter
- Determines if the method is a add or remove event listener method
- All promises from one or more promises
- Returns a promise that matches the given promises
- Add the hello world
- Print hello world
- Installs the load listener
elemental2 Key Features
elemental2 Examples and Code Snippets
Community Discussions
Trending Discussions on elemental2
QUESTION
I struggle with adding my custom jar to gwt compiler.
I've check tons of internet and can not find answer.
I found solution to add module.gwt.xml file to this custom jar library and import it in my gwt app app.gwt.xml as follow:
But this will make my custom java library gwt aware and this is anti pattern for me. As I will spoil backend common library with gwt (which is just UI detail).
I would like to follow approach with entry but I can configure it only for local java classes. I do not know how to do this for external jar.
Please help
Here are steps I've done already:
I've added source plugin to pom.xml of my custom jar as follow:
...ANSWER
Answered 2021-Dec-31 at 01:16You dont need to modify the jar, all you need is to create a gwt.xml file in your own project/client module that has its sources tag points to the pojos package.
What I would do is to create a package in my client module com.ia.ia.maintenance
and add a new gwt.xml there Maintenance.gwt.xml
QUESTION
I've ditched GWT Widgets in favor of JsInterop and Elemental2.
But I'm still using modules from "gwt-user.jar" for GSS, Resources, and I18N.
Are these modules likely to be supported in the next version of GWT? If not, is there a future-friendly alternative that I can use?
I'm just starting out, so I'd rather get it "right" now, than have to unpick it later on.
...ANSWER
Answered 2020-Sep-05 at 13:11If you are looking for a nice GWT3/J2CL ready widget lib, please take a look here: https://github.com/DominoKit/domino-ui.
You'll find a demo app here: https://demo.dominokit.org/home
Domino-ui is based on Elemento (https://github.com/hal/elemento) With Elemento you can create J2CL-ready widgets really easy.
Regarding your question about the modules: We are currently working on making the GWT modules J2CL ready. A few of them are already released to Maven Central as rc1. For more informations take a look here: https://docs.google.com/spreadsheets/d/15WXfiklnTeqjRLI8gKj5iyGk7iDhnuQHGcpYJgpNlmQ/edit#gid=0
and here:
https://docs.google.com/spreadsheets/d/1b1D9fEqRh5lZ8cqMJtYoc_25rfTRvsuJkTtS2vjgi3o/edit#gid=0
Our goal is to make the migration as easy as possible. Mostly just replacing com.google.gwt
with org.gwtproject
and GWT.create
statements with something like new ...Impl
. The new modules will work with GWT 2 & GWT 3/J2CL. At the moment a real drawback is, that only a few modules have made it's way to Maven Central. I would suggest to stay with the old modules and wait until the new modules are available in Maven Central.
There are two Gitter rooms that might be of interest you you:
QUESTION
I'm using GWT 2.9 with elemental2-1.0.0-RC1.
The following code throws a ClassCastException
at runtime:
ANSWER
Answered 2020-May-26 at 16:54Js.cast()
is a way to cheat a bit, and do something that the Java language will not permit, but might actually be legal. Ignoring "how it actually works", the idea is that you can now get past issues where Java would complain, even if it turns out to be legit.
An example could be where you take a java.lang.Double
or double
and want to treat it as a JsNumber
so you can call toPrecision(2) on it. Since java.lang.Double
is final, it isn't legal to cast to an unrelated type, but Java doesn't know that in GWT, Double is really just a js Number
. So, instead you can perform the cast with Js.cast()
. The compiler will insert a runtime type check in there, verifying at runtime that your number is in fact a JS Number instance.
Another example could be trying to extend some native type that elemental2 provides, either to implement a workaround for a missing feature, or to do something browser-specific. Your new class may not extend the existing class - from JS's perspective this is okay, you are just describing the API that you know will exist at runtime. As such, we need to avoid the Java language check of "does this cast even make sense?", and just tell the compiler to try it.
On the other hand, you can "lie" to the compiler with Js.uncheckedCast()
. This is used in cases where you are even asking the runtime to skip the check, and just pretend that it will work. This can let you do weird things, like treating Strings as if they were arrays, or solve cross-frame problems. No runtime check will be emitted, so instead you might just get a TypeError if a method/property is missing, instead of a proper ClassCastException.
In elemental2-dom 1.0.0-RC1, there is a class called DocumentRange
, but it doesnt really make any sense - it is declared as a class, which means it can be type checked in JS, but the browser spec says that it should be an "interface" (which in JS-land means that it just is a description of a type, rather than something you can typecheck). https://www.w3.org/TR/DOM-Level-2-Traversal-Range/ranges.html#Level2-DocumentRange-method-createRange
This bug is inherited from closure-compiler, which claims that this has a constructor: https://github.com/google/closure-compiler/blob/6a418aa/externs/browser/w3c_range.js#L241-L251
The fix is for closure-compiler to refer to this as an interface, and for a new release of elemental2 to be made so you can use this.
There are two workarounds you can make here. The first is to cheat with Js.uncheckedCast(DomGlobal.document)
and say "yes, I know that the Document
is not instanceof DocumentRange
, but that's because there is no such class as DocumentRange
, so just pretend it worked so I can call createRange()
on it". This is what you are doing already - it hides the fact there is a bug, but at the end of the day it works.
The "correct" answer is to declare your own DocumentRange
, and do a Js.cast()
to that instead. This is still gross - you have to keep your new interface around until closure gets fixed, and then elemental2 gets released, and then you have to remember to clean it up.
In this case, I would suggest lying to GWT and using Js.uncheckedCast()
- there is only a single method on here, and it is unlikely to change in a meaningful way.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install elemental2
If you want to modify and/or build the last version on your own, follow the instructions below:. The script will output the directory containing the generated jar files that can be used with maven.
Install Bazelisk:
Clone this git repository: $ git clone https://github.com/google/elemental2.git
Run the release script: $ cd elemental2 $ ./maven/release_elemental.sh --version local --no-deploy
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page