Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

geometry #20

Closed
wants to merge 5 commits into from
Closed

geometry #20

wants to merge 5 commits into from

Conversation

bitpshr
Copy link
Member

@bitpshr bitpshr commented Jun 2, 2015

This PR adds setters to @kfranqueiro's initial geometry getter work, along with tests. The actual setters could probably be refactored, but focus was put on readability.

* are positive, or smaller dimensions if they are negative.
*/
function adjustBox(box: ClientRect, top: number, right: number, bottom: number, left: number): ClientRect {
return {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be checking to make sure the width and height are non-negative, and that the right/bottom is >= left/top ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This internal function is only used for the get functions presently, and is always passed a result from getBoundingClientRect, so I don't think there's anything to validate here.

This point may be valid for the width/height in the set functions - Dojo 1 ignored them entirely if they were negative. Meanwhile, glancing at the Dojo 1 code, I'm not actually sure if/how it was ignoring width/height if they were undefined (which we are doing below), even though it documents them as optional.

@bitpshr
Copy link
Member Author

bitpshr commented Jun 2, 2015

refs #8

@kfranqueiro kfranqueiro added this to the Milestone 1 milestone Jun 2, 2015
@kfranqueiro kfranqueiro self-assigned this Jun 2, 2015
if (borderBox) {
height = rect.height;
}
else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be shortened to:

let height = rect.height;
if (!borderBox) {
    height -= ...
}

(and same for width)

@kfranqueiro
Copy link
Member

I can appreciate the focus on readability in this initial iteration, and I found myself debating whether some of the shortenings I suggested detract considerably from that. However, I think at the very least, shortening the code in setMarginBox may actually improve readability for that one given the common base in both cases.

It might be possible to shorten this more considerably, but I'd need to give my brain another iteration to catch that, and I suspect it'd involve some ugly <any> casts to get around our old favorite TS7017.

return {
'box-sizing: border-box': testBoxMethod('setBorderBox', 'border-box', expected),
'box-sizing: content-box': testBoxMethod('setBorderBox', 'content-box', expected)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon (same with the other setter tests)

@kfranqueiro kfranqueiro assigned bitpshr and unassigned kfranqueiro and bitpshr Jun 3, 2015
@eheasley eheasley modified the milestones: Milestone 1, Milestone 2 Jun 24, 2015
@eheasley eheasley removed this from the Milestone 1 milestone Jun 24, 2015
@kitsonk kitsonk modified the milestones: 2.0.0, Milestone 2 Mar 11, 2016
@kitsonk kitsonk modified the milestones: 2016.08, 2.0.0 Apr 8, 2016
@dylans dylans removed this from the 2016.08 milestone Oct 24, 2016
@dylans dylans added this to the long-grass milestone Jan 12, 2017
@kitsonk kitsonk closed this Sep 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants