I wonder, why must Layout inherit from Hash? I doubt that Hash enumeration  
methods would be used with Layout object, and don't see any other sense in  
that inheritance. Memoisation is done easily without that.

And if Layout object isn't a descendant of Hash, then there's no need to  
use get('width') syntax, and more autocomplete-friendly getWidth can be  
used.

On Fri, 16 Jan 2009 12:27:25 +0300, Andrew Dupont  
<[email protected]> wrote:

>
> I've just committed a couple large API additions in a "layout" branch
> in our Git repository:
>
> http://github.com/sstephenson/prototype/tree/layout
> http://github.com/sstephenson/prototype/blob/9d28f04d98307f652a2d85ff35e869f2e0ac7f38/src/dom/layout.js
>
> It's still very preliminary, but Element.Layout is meant to like a
> lazy-loading, memoized subclass of Hash. It gives measurements and
> offsets of practically any aspect an element's layout box. It's lazy-
> loading because some of these computations are costly and shouldn't be
> done unless strictly necessary.
>
> In other words, I can do something like this...
>
> var foo = $('foo');
> var layout = foo.getLayout();
>
> var width = layout.get('width'); // 144 (or some other number)
> var marginBoxWidth = layout.get('margin-box-width'); // 164 (content +
> padding + border + margin)
>
> Behind the scenes, it determined the "width" (i.e., the content box
> width) by taking the offsetWidth property from the element (which is
> the width of the element's "border box") and subtracting the computed
> padding and border widths on both sides. When it did this, it cached
> the values for many other measurements, like "border-box-width,"
> "padding-left," "padding-right," and so on. If any of these values are
> requested directly, no further computation is necessary.
>
> Furthermore, when we ask for the "margin-box-width" (i.e., the space
> the element truly commands), it knows it needs to fetch "margin-left"
> and "margin-right," but the values of all other properties are already
> cached.
>
> (A caveat: because of the caching, an Element.Layout object should be
> treated like a "snapshot" of an element's dimensions. When the
> dimensions of an object change, you ought to grab a new instance of
> Element.Layout.)
>
> Take a look at the code and tell me what you think. The API is far
> from complete, naturally, but it'd be great to know if people think
> this is the right idea.
>
> Cheers,
> Andrew
> >



-- 
arty ( http://arty.name )

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to