美文网首页
GWTP Presenter Slots 详解

GWTP Presenter Slots 详解

作者: 蒲印MkII | 来源:发表于2018-04-27 09:12 被阅读0次

在GWTP中有个概念被称作slots。

在子presenter被部署并且与它的父级presenter交互时,Slots基本上就是个占位符。
GWTP在暴露出 presenter时,同时使用递归策略调用定义的嵌套presenter层次结构中的每个生命周期方法。
在其层次结构中使用setInSlot(),使用递归策略调用定义的嵌套presenter层次结构中的每个生命周期方法。

Slot 类型:

1.SingleSlot Slot
只能承载一个presenter,可以使用 getChild(slot)来看slot里有什么

2.PermanentSlot
和singleslot差不多,但是只能管理有Proxies的slot

3.Slot
最宽松的slot,能装载多个presenter,能使用getChildren(slot)来查看它装载的具体信息

4.OrderedSlot
和slot差不多,但是这些presenter必须是可以比较的(comparable)。view会自动将它们排序,但是这些数据必须被绑定到一个IndexedPanel上。getChildren(slot)会按照顺序返回结果

5.PopupSlot
一个用于popup的slot。

如何使用:

在presenter中
slot需要被定义为一个field

static final Slot<PresenterWidget<?>> SLOT_CONTENT = new Slot<>();

如果要将ChildPresenter添加到已有的Presenter中的插槽中,请使用以下任一方法:

addToSlot():将会将Presenter附加到插槽中。
setInSlot():将替换插槽中的现有Presenter。

如果您在ParentPresenter中设置CurrentPresenter,通过在构造方法中使用一个NestedSlot的方式来完成。

@Inject
CurrentPresenter(
        EventBus eventBus,
        MyView view,
        MyProxy proxy) {
    super(eventBus, view, proxy, ParentPresenter.SLOT_CONTENT);
}

在view中:
您必须将您的插槽绑定到视图中的小部件。对于大多数使用情况,您可以简单地使用该bindSlot()方法:

@UiField
SimplePanel searchPanel;

@Inject
ApplicationView(
        Binder uiBinder) {
    initWidget(uiBinder.createAndBindUi(this));

    bindSlot(ApplicationPresenter.SLOT_CONTENT, searchPanel);
}

相关文章

网友评论

      本文标题:GWTP Presenter Slots 详解

      本文链接:https://www.haomeiwen.com/subject/sdxvlftx.html