如何保持“谦虚”的态度-使用具有特殊Oracle和建议的SuggestBox

发布于 2024-11-02 06:42:30 字数 892 浏览 6 评论 0原文

我学会了如何实现我自己的 SuggestionOracle("AuSuggestOracle") 和自己的 建议(“AuMultiWordSuggestion”)。就我而言,建议对象 是用DTO构建的。在选择活动中我需要这个 dto (或 它的某些领域)做出适当的反应。 我用这个特殊的方法实现了一个包含 3 个建议框的小部件 oracle 以及它们之间的一些逻辑。现在我想应用 MVP 模式 - 在演示者和视图中拆分此小部件。 目前演示者显示界面如下所示:

    public interface Display {
            HasSelectionHandlers<Suggestion> getFedLand();
            HasSelectionHandlers<Suggestion> getCounty();
            HasSelectionHandlers<Suggestion> getCommunity();
            AuSuggestOracle getFedLandOracle();
            AuSuggestOracle getCountyOracle();
            AuSuggestOracle getCommunityOracle();
            void clearCounty();
            void clearCommunity();
            void activateForm();
            Widget asWidget();
    }

问题是方法中关于我的模型的隐式知识 返回“AuSuggestOracle”。所以我的问题是如何获取视图/ 界面“简陋”。就我而言,显示的建议字符串是 不明确,我至少需要所选项目的“id”才能知道什么 选择 DTObject。

i learned how to implement my own SuggestionOracle("AuSuggestOracle") and own
Suggestions("AuMultiWordSuggestion"). In my case the suggestion object
is constructed with a DTO. On a selection event i need this dto (or
some fields of it) to react appropriate.
I implemented a widget containing 3 suggest boxes with this special
oracle and some logic between them. Now i want to apply MVP pattern -
split this widget in presenter and view.
At the moment the presenters display interface look like that:

    public interface Display {
            HasSelectionHandlers<Suggestion> getFedLand();
            HasSelectionHandlers<Suggestion> getCounty();
            HasSelectionHandlers<Suggestion> getCommunity();
            AuSuggestOracle getFedLandOracle();
            AuSuggestOracle getCountyOracle();
            AuSuggestOracle getCommunityOracle();
            void clearCounty();
            void clearCommunity();
            void activateForm();
            Widget asWidget();
    }

the problem is the implicit knowledge about my model in methods
returning "AuSuggestOracle". so my question is how to get the view/
interface "humble". in my case the displayed suggestion-strings are
ambiguous and i need at least the "id" of a selected item to know what
DTObject is selected.

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

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

发布评论

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

评论(1

风启觞 2024-11-09 06:42:30

我解决这个问题的方法是省略 Oracle 的吸气剂,因为一旦我的演示者设置了它,我的视图就不需要任何有关它的信息。所以,我的界面如下所示:

public interface Display {
    ...

    void setSuggestionOracle(SuggestOracle oracle);
    HasSelectionHandlers<SuggestOracle.Suggestion> getSelectionListener();
}

我遇到的问题是在实例化后能够将建议添加到 SuggestBox 中。为了解决这个问题,我使用一个空白的 SuggestBox 进行初始化,然后将其从视图中删除、更新,然后将其插回原位。

之后,您可以编写处理程序(在演示者中)来检查建议是否是您的自定义建议的实例,并且您的演示者可以处理选择并将相关信息推送回您的视图。

通过这样做,您的所有视图都知道它将接受某些内容的通用建议,并且在稍后的某个时间它将更新信息(这将是建议的结果,但视图是“谦虚”)知道这一点)。

The way I got around this is by leaving out the getters for the Oracle since once my presenter sets it my view doesn't need any information about it. So, my interface looked like this:

public interface Display {
    ...

    void setSuggestionOracle(SuggestOracle oracle);
    HasSelectionHandlers<SuggestOracle.Suggestion> getSelectionListener();
}

The problem I encountered was being able to add the suggestion to the SuggestBox after it was instantiated. To get around this, I initialized with a blank SuggestBox and then removed it from the view, updated in, and inserted it back into position.

After that, you can write your handler (in the presenter) to check if the suggestion is an instance of your custom suggestion and your presenter can handle the selection and push the relevant information back down to your view.

By doing this, all your view knows is that it will be taking generic suggestions for something, and that at some later time it will be updating with information (which will be as a result of the suggestion, but the view is to 'humble' to know that).

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