GWT RunAsync - 发布模式下的奇怪行为
正如这个问题所建议的 GWT - 哪里我应该在使用地方/活动/映射器时使用代码分割吗?,我创建了一个 ActivityProxy 来嵌套我的活动。
我的实现基于此 http://code。 google.com/p/google-web-toolkit/issues/detail?id=5129(第 6 条评论),有一项修改:我在调用 GWT.RunAsync 之前添加了对提供程序的检查:
if (provider != null)
{
GWT.runAsync(new RunAsyncCallback()
{
@Override
public void onFailure(Throwable reason)
{
// ...
}
@Override
public void onSuccess()
{
ActivityProxy.this.nestedActivity = provider.create();
//...
}
});
}
但由于某种原因,这在发布模式下不起作用:永远不会调用 onFailure 方法,但我的活动在我第一次使用它时永远不会显示。如果我重新加载该位置,一切都会显示得很好。
然后我意识到执行以下操作可以解决问题:
GWT.runAsync(new RunAsyncCallback()
{
@Override
public void onFailure(Throwable reason)
{
// ...
}
@Override
public void onSuccess()
{
if (provider != null)
{
ActivityProxy.this.nestedActivity = provider.create();
//...
}
}
});
因此,即使我不明白它为什么有效,我也开始将它用于我的所有活动。
当我决定为我的 ActivityProxy 使用生成器(以避免为每个 Activity 编写提供程序)时,我再次遇到了这个问题。合成器变成 GWT.create(ActivityProxy).wrap(MyActivity.class);
基本上,生成的代码如下所示:
if (clazz.getName() == "FooClass")
{
nestedActivity = new FooClass(); //inside a RunAsync
}
if (clazz.getName() == "BarClass")
{
nestedActivity = new BarClass(); //inside a RunAsync
}
并且出现同样的问题:我的应用程序第一次无法显示我的活动被使用。
如此简单的问题:“为什么?”
As suggested in this question GWT - Where should i use code splitting while using places/activities/mappers?, I created an ActivityProxy to nest my activities.
I based my implementation on this http://code.google.com/p/google-web-toolkit/issues/detail?id=5129 (6th comment), with one modification: I added a check on the provider before calling GWT.RunAsync:
if (provider != null)
{
GWT.runAsync(new RunAsyncCallback()
{
@Override
public void onFailure(Throwable reason)
{
// ...
}
@Override
public void onSuccess()
{
ActivityProxy.this.nestedActivity = provider.create();
//...
}
});
}
But for some reason, this doesn't work in release mode: the onFailure methode is never called but my activity is never displayed the first time I use it. If I reload the place, everything display just fine.
Then I realised that doing the following solves the problem:
GWT.runAsync(new RunAsyncCallback()
{
@Override
public void onFailure(Throwable reason)
{
// ...
}
@Override
public void onSuccess()
{
if (provider != null)
{
ActivityProxy.this.nestedActivity = provider.create();
//...
}
}
});
So even if I don't understand why it works, I started using it for all my activities.
I ran into the problem again when I decided to use a generator for my ActivityProxy (to avoid writing a provider for each Activity). The synthax becomes GWT.create(ActivityProxy).wrap(MyActivity.class);
Basically, the generated code looks like this:
if (clazz.getName() == "FooClass")
{
nestedActivity = new FooClass(); //inside a RunAsync
}
if (clazz.getName() == "BarClass")
{
nestedActivity = new BarClass(); //inside a RunAsync
}
And the same problem occurs: my app fails to display my activities the first time they are used.
So simple question : "Why?"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论