Will refer to one ClientBundle class from several UiBinders?

I have one ClientBundle with css resources that are needed throughout the application - default background colors, general layout templates, etc.

GWTโ€™s announced "> project goal " is that "there is no penalty for multiple ClientBundle resource functions related to the same content." Do I need to do anything to avoid fines and help ClientBundle realize this goal ?

A naive approach would be to simply add

<ui:with field="appWideResources" type='com.activegrade.client.resources.appwide.AppWideResources' /> 

at the top of each UiBinder file. But in my 22 millionth UiBinder files, will this create 22 million instances of AppWideResources, each of which has different and redundant obfuscations, etc.?

+4
source share
1 answer

You can do it this way or with the @UiFactory method, and nothing will cost you anything extra. GWT will only instantiate the resource once and share this single instance with every file that references this set.

"... every time you call GWT.create() (which will execute ui:with ), it will instantiate a new object, but all resources in the ClientBundle initialized as static fields, so each instance is only very lightweight" proxy "for these static fields, and the GWT compiler optimizes it at the end (almost), as if you had a singleton instance." (Thomas Broyer)

+5
source

Source: https://habr.com/ru/post/1383946/


All Articles