2016-07-15 118 views
0

我是GWT和GWTP的新手。我知道什么是GWT代码拆分和GWTP代理代码拆分。我已经红:@ProxyCodeSplit它的工作原理是什么?

http://www.gwtproject.org/doc/latest/DevGuideCodeSplitting.html http://dev.arcbees.com/gwtp/core/presenters/creating-places.html

我认为我理解这一点。所以我喜欢用。:

我有Administration panel的应用程序,只有部分用户可以访问。所以没有必要为所有人下载Administration panel相关的代码。因此,在Administration Presenter我添加@ProxyCodeSplit像如下:

public class AdminAreaPresenter extends Presenter<AdminAreaPresenter.MyView, AdminAreaPresenter.MyProxy> { 
    @ProxyCodeSplit 
    @NameToken(Routing.Url.admin) 
    @UseGatekeeper(IsAdminGatekeeper.class) 
    public interface MyProxy extends TabContentProxyPlace<AdminAreaPresenter> {} 

    @TabInfo(container = AppPresenter.class) 
    static TabData getTabLabel(IsAdminGatekeeper adminGatekeeper) { 
     return new MenuEntryGatekeeper(Routing.Label.admin, 1, adminGatekeeper); 
    } 

    public interface MyView extends View {} 

    AppPresenter appPresenter; 

    @Inject 
    AdminAreaPresenter(EventBus eventBus, MyView view, MyProxy proxy, AppPresenter appPresenter) { 
     super(eventBus, view, proxy, AppPresenter.SLOT_TAB_CONTENT); 
     this.appPresenter = appPresenter; 
    } 
} 

在其他的演讲者我有@ProxyStandard而不是@ProxyCodeSplit。 。 enter image description here

,你可以:在应用程序中打开Administation Panel

enter image description here

和:

我已经运行的应用程序并登录,然后我打开Network标签在Chrome的开发者控制台看,没有新的资源添加到应用程序。

我的主应用程序发布者AppPresenter实现从com.gwtplatform.mvp.client.proxy接口AsyncCallStartHandler, AsyncCallFailHandler, AsyncCallSucceedHandler。我覆盖这些方法:

@ProxyEvent 
@Override 
public void onAsyncCallStart(AsyncCallStartEvent event) { 
    Window.alert("Async start"); 
    getView().setTopMessage("Loading..."); 
} 
@ProxyEvent 
@Override 
public void onAsyncCallFail(AsyncCallFailEvent event) { 
    Window.alert("Async fail"); 
    getView().setTopMessage("Oops, something went wrong..."); 
} 
@ProxyEvent 
@Override 
public void onAsyncCallSucceed(AsyncCallSucceedEvent event) { 
    Window.alert("Async success"); 
    getView().setTopMessage(null); 
} 

当我进入AdmininArea我正在给allerts:“异步启动”,“异步成功”。所以我认为这个想法是可行的,但不幸的是我看不到任何资源上的变化。请帮忙。我做错了什么?

+1

你在调试模式(超级开发模式)下使用生产编译来测试它吗?调试模式代码分割中的AFAIK被禁用。 –

+0

我只在超级开发模式下测试过它。你的意思是'禁用'整个src是一次下载的。或者每当我更换有代码拆分的地方时下载? - 正在发生这种情况 – masterdany88

+1

将不会生成任何代码拆分点,并且整个应用程序一次性被卸载。如果您更改任何代码,SDM将重新编译该应用程序,并再次下载整个代码。为了测试代码拆分,请尝试在生产模式下运行它。 –

回答

1

代码拆分在SuperDevMode中被禁用,因为它与增量式编译器不兼容,也会减慢编译速度(请参阅此issue)。

要测试代码分裂,编译GWT应用程序(mvn clean install gwt:compile)和生产模式(以从目标目录war文件,并把它放在f.e:Tomcat服务器目录:webapps)进行测试。

相关问题