Multiple views update the same VO in Model

ps's Avatar

ps

15 Nov, 2011 04:01 PM

Hi!

I know that it is not a new problem but I don't know how to name it so I can't find it. I know that some time ago I've encountered this I but don't remember where.

I have 4 different views which update the same VO in Model. When VO changes it dispatches signal which is listened by all those 4 views.
What I would like to optimize: When 1 view is edited I don't want the value to go around through Model and back to this view. It should dispatch to model and change internally.

How do I manage that?

ps

  1. 1 Posted by Pierre Laveklin... on 15 Nov, 2011 04:51 PM

    Pierre Laveklint's Avatar

    Hey,

    First of, your views Mediators are listening to changes on the model right and like you said: "views listening to changes to the same VO" ?

    Other things aside:
    If the new value of the VO is changed, you could put a bit of view-logic to check if the value coming in is the same as the current view-value, then do nothing...

    Might be more of help if you posted some reference code.

    /Pierre

  2. 2 Posted by Pierre Laveklin... on 15 Nov, 2011 04:53 PM

    Pierre Laveklint's Avatar

    *"and not like you said..."

  3. 3 Posted by ps on 15 Nov, 2011 06:20 PM

    ps's Avatar

    Hi Pierre!

    Yeah, so more explanations would be better. Ive ommited all the RL logic view>mediator>command>model>mediator>view, couse I dont want to complicate. But Im doing it like this.

    More details to make it clear: I have an object which properties are visualized in 4 different places: 2D, 3D, properties panel, and quick menu. So if I change eg. x position in properties it should change in 2D (if current). If 3D view is current one and I move the object, it should update properties panel and when I switch to 2D view it also should be updated.

    And as I said before: When 1 view is edited I don't want the value to go around through Model and back to this view. It should dispatch to model and change internally.

    ps

  4. 4 Posted by Pierre Laveklin... on 15 Nov, 2011 06:33 PM

    Pierre Laveklint's Avatar

    Ok:
    ( bare with me, written on my iPhone ) AView {

    changeSignal.dispatch( aPayload );
    

    }

    AMediator {

    view.changeSignal.add( onChange );
    eventMap.mapListener( ModelEvent.PROPS_CHANGED, onPropsChanged );
    
    onChange( inPayload ):void
    {
        injectedModel.setProps( inPayload );
        view.setReflectedProps( inPayload );
    }
    
    onPropsChanged( event:Event ):void
    {
        // nasty mediator logic
        var pl:Payload = event.payLoad;
        if( view.props != pl )
            view.setReflectedProps( inPayload );
    }
    

    }

    Does that make sense or am I am I on the wrong track?

  5. 5 Posted by ps on 15 Nov, 2011 06:59 PM

    ps's Avatar

    Looks that it will work, I dont see any unnecessary actions. That should do the trick! Thanks Pierre!

  6. ps closed this discussion on 15 Nov, 2011 06:59 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac