robotlegs: I have 2 views and mediators that have in common 1 thing how can I DRY it?

StackOverflow https://stackoverflow.com/questions/4111258

  •  29-09-2019
  •  | 
  •  

Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top