Robotlegs:我有 2 个观点和调解者,它们有 1 个共同点,我该如何干燥它?

发布于 2024-10-01 01:49:02 字数 1519 浏览 5 评论 0原文

我有两个视图显示列表,然后使用中介来获取数据。但我想以某种方式干燥它,这样我就不必为同一件事重复两次。我该怎么做?

EDIT1(code):

[SkinPart(required="false")]
public var WOListsDDL:DropDownList;
    // in partadded
case WOListsDDL:
    // when the selected list is changed in the lists drop down list
    WOListsDDL.addEventListener(IndexChangeEvent.CHANGE, _WOListsDDL_changeHandler);
    WOListsDDL.dataProvider = new ArrayCollection();
    WOListsDDL.labelField = 'title';
break;
    //

    protected function _WOListsDDL_changeHandler(event:*):void{
        _debug('List selection changed handler.');
        _getContentsForList();
    }
    protected function _getContentsForList():void{
        _debug('Getting list items.');
        getItemsSignal.dispatch({key: getSelectedList()._key, itemType: 'item'});
    }
    public var getItemsSignal:GetItemsSignal = new GetItemsSignal();

    override public function mediatorComplete():void{
        getItemsSignal.dispatch({key: tottysAuth.getCurrentUser()._key, itemType: 'list'});
    }

// 然后在我的中介器中,

    [Inject] public var getItemsSignal:GetItemsSignal;
    override public function onRegister():void{
        // view listeners
        view.getItemsSignal.add(_getItemsSignalHandler);
    }
    protected function _getItemsSignalHandler(input:Object):void{
        getItemsSignal.dispatch(input);
    }

这一切都针对一个视图中介器。现在我有 2 个视图中介正在执行这些任务。如何让它们干燥?

我有的解决方案: 创建一个包含下拉列表的小视图,其中包含正在侦听事件的中介器。在大组件中,它们在这个小组件的视野中监听信号。而已。看起来不错,但我觉得不是那么好

I have 2 views that show lists that then uses a mediator to get data. but I want in some way to DRY it so I don't have to repeat my self 2 times for the same thing. how do I do it?

EDIT1(code):

[SkinPart(required="false")]
public var WOListsDDL:DropDownList;
    // in partadded
case WOListsDDL:
    // when the selected list is changed in the lists drop down list
    WOListsDDL.addEventListener(IndexChangeEvent.CHANGE, _WOListsDDL_changeHandler);
    WOListsDDL.dataProvider = new ArrayCollection();
    WOListsDDL.labelField = 'title';
break;
    //

    protected function _WOListsDDL_changeHandler(event:*):void{
        _debug('List selection changed handler.');
        _getContentsForList();
    }
    protected function _getContentsForList():void{
        _debug('Getting list items.');
        getItemsSignal.dispatch({key: getSelectedList()._key, itemType: 'item'});
    }
    public var getItemsSignal:GetItemsSignal = new GetItemsSignal();

    override public function mediatorComplete():void{
        getItemsSignal.dispatch({key: tottysAuth.getCurrentUser()._key, itemType: 'list'});
    }

// then in my mediator

    [Inject] public var getItemsSignal:GetItemsSignal;
    override public function onRegister():void{
        // view listeners
        view.getItemsSignal.add(_getItemsSignalHandler);
    }
    protected function _getItemsSignalHandler(input:Object):void{
        getItemsSignal.dispatch(input);
    }

this all for one view-mediator. now I have 2 view-mediators that are doing these tasks. How to make them dry?

Solutions I have:
make a little view containing the dropdown list with a mediator that is listening for the event. in the big components they are listening for a signal in the view of this little component. nothing more. it seems quite well but i don't think is so great

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

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

发布评论

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

评论(1

梦屿孤独相伴 2024-10-08 01:49:02

那么视图和中介器上都有一些您不想重复的功能吗?

您可以将要重用的代码放在另一个对象中,并从多个视图和中介器中调用其方法。或者,您可以将其放入祖先类中,并在您的视图和中介器中扩展每个类。

最佳实践是执行前者而不是后者。

So there is functionality on both the views and the mediators that you'd like not to repeat?

You could put the code you want to reuse in another object and call its methods from your multiple views and mediators. Or you could put it in ancestor classes and extend each of those classes in both your view and your mediator.

Best practice would be to do the former and not the latter.

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