[Laszlo-dev] For Review: Change 20071016-hqm-4 Summary: fix for DHTML replication bug

P T Withington ptw at pobox.com
Tue Oct 16 14:29:10 PDT 2007


Something like this:

>         var f = function (){
>             this.setAttribute( "y" , this.immediateparent.height /2
>                                 - this.height /2);
>         }
>         f.dependencies = function (target) {
>           return [target.immediateparent, 'height', target, 'height'];
>         }
>         this.applyConstraint('x', f);

I.e., create a dependencies function for these functions.  You could  
be clever with these functions and use a closure to decide whether to  
divide by 2 for 'middle', etc. and reduce the lines of code a bunch.

> function setValign ( valign ){
>   var factor = 1;
>   if ( valign == "top" ) {
>     this.releaseConstraint('y');
>     this.setAttribute('y', 0);
>     return;
>   } else if ( valign == "middle" ){
>     var factor = 2;
>   } else if ( valign == "bottom" ){
>   } else {
>     Debug.error("Invalid value %w for %s.valign", valign, this);
>   }
>   var f = function (){
>     this.setAttribute( "y" , this.immediateparent.height / factor
>                        - this.height / factor);
>   }
>   f.dependencies = function (target) {
>     return [target.immediateparent, 'height', target, 'height'];
>   }
>   this.applyConstraint('y', f);
> }

Also, the target is just the this argument to applyConstraint, so you  
don't really need to pass a separate target parameter, I guess.


On 2007-10-16, at 16:52 EDT, Henry Minsky wrote:

> That makes sense, to pass the object down instead of the  
> dependencies list.
> There's only a couple of callers to applyConstraint right now, but  
> one of
> them is this one caller in LaszloView that makes it's own  
> dependencies list:
>
> function setPosConstraint ( v , f , widthorheight ){
>     var d = [ v , widthorheight  , this , widthorheight ];
>     this.applyConstraint( widthorheight == "width" ? "x" : "y" ,  
> f , d );
> }
>
>
> How do think I should handle that? I could make an object and put a
> .dependencies on it and pass that I guess.
>
> On 10/16/07, P T Withington <ptw at pobox.com> wrote:
>>
>> In fact, wouldn't it make more sense to move all the logic about
>> dependencies inside applyConstraint so it will be handled correctly
>> in one place and update all the callers?  I see no reason to have the
>> callers compute the dependencies out of line, you just need to pass
>> the target (this) down to applyConstraint.
>>
>> On 2007-10-16, at 16:40 EDT, P T Withington wrote:
>>
>>> Not approved.
>>>
>>> 1) This code should be modeled on the known-working code in LzNode:
>>>
>>>>         if (rp instanceof Function && ('dependencies' in rp)) {
>>>>             this.applyConstraint( p , rp , rp.dependencies.call
>>>> (this) );
>>>>         }
>>>
>>> rather than creating the mystery `_t` attribute.
>>>
>>> 2) There seems to be another branch of the code that replicates the
>>> same bug which should also be rewritten in modern style.
>>>
>>> 3) What about the case of a $once constraint?  Will it be handled
>>> correctly?  In LzNode when there are no dependencies, the
>>> constraint function is still called at least once.  I don't see in
>>> this code where that is handled.
>>>
>>> On 2007-10-16, at 15:24 EDT, Henry Minsky wrote:
>>>
>>>> Change 20071016-hqm-4 by hqm at IBM-2E06404CB67 on 2007-10-16
>>>> 15:19:46 EDT
>>>>     in /cygdrive/c/users/hqm/openlaszlo/trunk
>>>>     for http://svn.openlaszlo.org/openlaszlo/trunk
>>>>
>>>> Summary: fix for DHTML replication bug
>>>>
>>>> New Features:
>>>>
>>>> Bugs Fixed: LPP-4893
>>>>
>>>> Technical Reviewer: andre
>>>> QA Reviewer: ptw
>>>> Doc Reviewer:
>>>>
>>>> Documentation:
>>>>
>>>> check for null dependencies function before calling it
>>>>
>>>> Release Notes:
>>>>
>>>> Details:
>>>>
>>>>
>>>> Tests:
>>>>
>>>> test case from bug, smokecheck, amazon app
>>>>
>>>> Files:
>>>> M      WEB-INF/lps/lfc/data/LzReplicationManager.lzs
>>>>
>>>> Changeset: http://svn.openlaszlo.org/openlaszlo/patches/20071016-
>>>> hqm-4.tar
>>>>
>>>>
>>>> --
>>>> Henry Minsky
>>>> Software Architect
>>>> hminsky at laszlosystems.com
>>>
>>
>>
>
>
> -- 
> Henry Minsky
> Software Architect
> hminsky at laszlosystems.com



More information about the Laszlo-dev mailing list