Will referring to a single ClientBundle class from multiple UiBinders cost anything?

别等时光非礼了梦想. 提交于 2019-12-10 15:37:06

问题


I have a single ClientBundle with css resources that are needed throughout the application - default background colors, common layout patterns, etc.

A stated design goal from GWT is that there be "no penalty for having multiple ClientBundle resource functions refer to the same content." Do I have to do anything to avoid penalties and help ClientBundle realize this goal?

A naive approach would be to just add

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

at the top of every UiBinder file. But, in my 22 jillion UiBinder files, will this create 22 jillion instances of AppWideResources, each with different and redundant obfuscations, etc?


回答1:


You could do it that way or via the @UiFactory method, and neither would cost you anything additional. GWT will only instantiate a resource set once and share that single instantiation with every file that references that set.

"...each time you call GWT.create() (which a ui:with will do) it will instantiate a new object, but all resources in the ClientBundle are initialized as static fields, so each instance is only a very lightweight "proxy" to those static fields; and the GWT compiler will optimize it out in the end, (almost) as if you had a singleton instance." (Thomas Broyer)



来源:https://stackoverflow.com/questions/8330660/will-referring-to-a-single-clientbundle-class-from-multiple-uibinders-cost-anyth

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!