« Return to Thread: Strugging with Commands

Re: Strugging with Commands

by Keithy :: Rate this Message:

Reply to Author | View in Thread

Lukas Renggli wrote:

>>>> I am struggling to write a command which edits a model, rather than
>>>> the
>>>> command instance itself. I am trying to do it this way since the  
>>>> model
>>>> class and description may change whereas the command class does not.
>>>>
>>>>        
>>> Why do you use a command then? As described in the GOF book, this
>>> design pattern is used to encapsulate an action and its parameters.
>>>      
>> It does encapsulate an action. The problem being that commands as they
>> are can only act upon themselves.
>>    
>
> Why do you think that? All commands I know act on other objects,  
> mostly on structures in Pier.
>
> Cheers,
> Lukas
>  
I must choose my words more carefully: they can only display themselves,
since the value returned from the component must be a command or nil.

Here is my solution....

PRContentsWidget-i-buildComponent: aContext
    ^ aContext command asComponent
        onAnswer: [ :value | aContext command onAnswerValue: value to:
self ];
        yourself


PRCommand-i-onAnswerValue: componentReturnValue to: widget

"componentReturnValue is typically but not necessarily a command"  

componentReturnValue isNil
        ifTrue: [ ^ widget context: (widget context structure: widget
context structure) ].
    [ componentReturnValue execute ]
        on: Error
        do: [ :err |
             
            Preferences debugPierFormErrors ifTrue: [ err pass ].
           
            ^ widget component errors add: err.  ].
       
    widget context: componentReturnValue answer

=========
what do you think?

Keith










_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki

 « Return to Thread: Strugging with Commands

LightInTheBox - Buy quality products at wholesale price