Copying Descriptions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Copying Descriptions

keith1y
If I want to do...


===
formDescriptionNewUserRegistration

    | loginDesc |

    loginDesc := self description copy.
       
    (loginDesc atLabel: 'Username')
        beWriteable;
        beRequired;
        addCondition: [ :newUserName |
            self client login isLoginUsernameAvailable: newUserName ]
        labelled: 'already taken'.
       
    ^ loginDesc
   
=====

The copy is needed, because I dont want to modify the cached version,
that everyone else is using. However, I dont think that the children are
copied, they remain the same objects.

Could/should they be copied in MAContainer-#postCopy ?

Keith


_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Copying Descriptions

keith1y
If I want to do...

>
> ===
> formDescriptionNewUserRegistration
>
>     | loginDesc |
>
>     loginDesc := self description copy.
>        
>     (loginDesc atLabel: 'Username')
>         beWriteable;
>         beRequired;
>         addCondition: [ :newUserName |
>             self client login isLoginUsernameAvailable: newUserName ]
>         labelled: 'already taken'.
>        
>     ^ loginDesc
>    
> =====
>
> The copy is needed, because I dont want to modify the cached version,
> that everyone else is using. However, I dont think that the children are
> copied, they remain the same objects.
>
> Could/should they be copied in MAContainer-#postCopy ?
>
> Keith
>  
ok since children is a sorted collection, that makes copying needlessly
expensive for this use case.
I have adopted the following idiom.

#formDescriptionForgottonPassword

    ^ self description
        atLabel: 'E-mail'         modify: [ :d | d componentClass:
MATextInputComponent ];
        atLabel: 'Username'    modify: [ :d | d beWriteable ];
        atLabel: 'Password'     modify: [ :d | d beHidden ];
        yourself


Keith


_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Copying Descriptions (minor fix)

keith1y
In reply to this post by keith1y
If I want to do...

>
> ===
> formDescriptionNewUserRegistration
>
>     | loginDesc |
>
>     loginDesc := self description copy.
>        
>     (loginDesc atLabel: 'Username')
>         beWriteable;
>         beRequired;
>         addCondition: [ :newUserName |
>             self client login isLoginUsernameAvailable: newUserName ]
>         labelled: 'already taken'.
>        
>     ^ loginDesc
>    
> =====
>
> The copy is needed, because I dont want to modify the cached version,
> that everyone else is using. However, I dont think that the children are
> copied, they remain the same objects.
>
> Could/should they be copied in MAContainer-#postCopy ?
>
> Keith
>  
ok since children is a sorted collection, that makes copying needlessly
expensive for this use case.
I have adopted the following idiom.

#formDescriptionForgottonPassword

    ^ self description copy
        atLabel: 'E-mail'         modify: [ :d | d componentClass:
MATextInputComponent ];
        atLabel: 'Username'    modify: [ :d | d beWriteable ];
        atLabel: 'Password'     modify: [ :d | d beHidden ];
        yourself


Keith




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