为什么我需要覆盖“onPlaceRequest”在每个演示者课程中?

发布于 2024-11-18 17:56:24 字数 959 浏览 1 评论 0原文

我通过 Places 管理项目中的历史记录。

我所做的是:

  • 在顶层实现 PlaceRequestHandler (例如 AppController),
  • 注册它 -> eventBus.addHandler(PlaceRequestEvent.getType(), this);
  • 实现方法“onPlaceRequest”,我在其中进行项目导航。

我正在使用 GWT 演示器,项目中的每个演示器都会重写 onPlaceRequest 方法。

当每个请求都是从顶级“onPlaceRequest”方法处理时,为什么我需要这个?

我将举一个例子:

public class AppController implements Presenter, PlaceRequestHandler
...........
public void bind()
{
  eventBus.addHandler(PlaceRequestEvent.getType(), this);
...
}
public void onPlaceRequest(PlaceRequestEvent event)
{
// here is the project navigation tree
} 

让我们以一位演示者为例

public class SomePresenter extends Presenter<SomePresenter.Display>
{
... here some methods are overriden and 

@Override
protected void onPlaceRequest(PlaceRequest request)
{
// what should I do here? 
}
}

,这个想法是什么,以及我应该如何做使用它吗?

I'm managing the History in my project via Places.

What I do is this:

  • implement PlaceRequestHandler on top level (for example AppController),
  • register it -> eventBus.addHandler(PlaceRequestEvent.getType(), this);
  • implement method "onPlaceRequest" ,where i do project navigation.

I'm using GWT presenter and every presenter in my project overrides the onPlaceRequest method.

Why do I need this, when every request is handled from the top level "onPlaceRequest" method?

I will give an example:

public class AppController implements Presenter, PlaceRequestHandler
...........
public void bind()
{
  eventBus.addHandler(PlaceRequestEvent.getType(), this);
...
}
public void onPlaceRequest(PlaceRequestEvent event)
{
// here is the project navigation tree
} 

and let's take one presenter

public class SomePresenter extends Presenter<SomePresenter.Display>
{
... here some methods are overriden and 

@Override
protected void onPlaceRequest(PlaceRequest request)
{
// what should I do here? 
}
}

What is the idea, and how I'm supposed to use it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终遇你 2024-11-25 17:56:25

您可以将 PlaceHistoryHandlerPlaceController 附加到事件总线,而不是让所有演示者扩展 PlaceRequestHandler 并自己管理这些事件。它们共同为您管理浏览器的历史记录和位置。当您要求 PlaceController goTo() 到另一个地点时,它将停止您当前的活动并使用地点到活动(您的演示者)的映射来选择下一个开始的活动。

要使用此技术,您需要让演示者扩展 AbstractActivity。尝试按照 GWT 文档中的 Google 教程进行操作,名为使用 Activity 和 Places 进行 GWT 开发。

Instead of making all of your presenters extend PlaceRequestHandler and managing those events yourself, you can attach a PlaceHistoryHandler and a PlaceController to your event bus. Together, they manage the browser's history and your places for you. When you ask your PlaceController to goTo() a different place, it will stop your current activity and use a mapping of places to activities (your presenters) to choose which one to start next.

To use this technique, you need to have your presenters extend AbstractActivity. Try following through Google's tutorial about it in GWT's documentation called GWT Development with Activities and Places.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文