Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify widget render #336

Merged
merged 14 commits into from
Nov 1, 2017
Merged

Simplify widget render #336

merged 14 commits into from
Nov 1, 2017

Conversation

smhigley
Copy link
Contributor

Type: feature

The following has been addressed in the PR:

  • There is a related issue
  • All code matches the style guide
  • Unit or Functional tests are included in the PR

Description:

Resolves #316

Makes widgets more easily extensible by simplifying the render code, particularly addressing these points from the issue:

  • break out large chunks of rendered dom
  • state classes are returned in a function
  • icons are broken out
  • inline styles are calculated separately

Copy link
Member

@bitpshr bitpshr left a comment

Choose a reason for hiding this comment

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

A few subjective observations / suggestions, but this is ready to land. I made #343 to track the removal of all other sub-widgets.

@@ -70,6 +70,30 @@ export default class Button extends ButtonBase<ButtonProperties> {
private _onTouchEnd (event: TouchEvent) { this.properties.onTouchEnd && this.properties.onTouchEnd(event); }
private _onTouchCancel (event: TouchEvent) { this.properties.onTouchCancel && this.properties.onTouchCancel(event); }

protected getContent() {
Copy link
Member

Choose a reason for hiding this comment

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

It may be nice to embrace ES getters if no arguments are passed to these:

get content() {
    return this.children;
}

Copy link
Member

Choose a reason for hiding this comment

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

i'd say this is overkill @bitpshr especially if the getter ends up doing more than simply getting.

Copy link
Member

Choose a reason for hiding this comment

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

Fair.

return w(CalendarCell, {
key: `date-${dateIndex}`,
key: `date-${date}${active ? '' : '-dimmed'}`,
Copy link
Member

Choose a reason for hiding this comment

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

Why was this change necessary?

Copy link
Contributor Author

@smhigley smhigley Nov 1, 2017

Choose a reason for hiding this comment

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

when I moved rendering the actual date cell into its own function (renderDateCell), I didn't have access to the index any more. It seemed overkill to pass it in just for the key when I could also generate a unique key based on the date and currentMonth.

@@ -16,7 +16,6 @@ import * as iconCss from '../common/styles/icons.m.css';
*
* Properties that can be set on a Calendar component
*
* @property CustomDateCell Custom widget constructor for the date cell. Should use CalendarCell as a base.
Copy link
Member

Choose a reason for hiding this comment

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

Did you remove sub-widgets as part of this PR as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is sub-widgets make it much easier to handle data binding on event handlers (e.g. onClick on a specific date cell returns the correct date and disabled state). Based on talking with Ant, I think the compromise reached was to leave in sub-widgets, but try not to expose them to the user

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've been wondering if it makes sense to remove the typedoc for CalendarCell. It's marginally useful to developers wanting to extend CalendarCell, but I definitely don't want it showing up in Dojo documentation

@@ -70,6 +70,30 @@ export default class Button extends ButtonBase<ButtonProperties> {
private _onTouchEnd (event: TouchEvent) { this.properties.onTouchEnd && this.properties.onTouchEnd(event); }
private _onTouchCancel (event: TouchEvent) { this.properties.onTouchCancel && this.properties.onTouchCancel(event); }

protected getContent() {
Copy link
Member

Choose a reason for hiding this comment

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

i'd say this is overkill @bitpshr especially if the getter ends up doing more than simply getting.

});
}

protected renderPagingButtonContent(type: 'next' | 'previous') {
Copy link
Member

Choose a reason for hiding this comment

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

next / previous would be better as a string enum

@@ -191,7 +191,38 @@ export default class DatePicker extends DatePickerBase<DatePickerProperties> {
onPopupChange && onPopupChange(this._getPopupState());
}

private _renderMonthRadios() {
protected renderControlsTrigger(type: 'month' | 'year'): DNode {
Copy link
Member

Choose a reason for hiding this comment

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

string enum

@@ -215,7 +246,20 @@ export default class DatePicker extends DatePickerBase<DatePickerProperties> {
]));
}

private _renderYearRadios() {
protected renderPagingButtonContent(type: 'next' | 'previous') {
Copy link
Member

Choose a reason for hiding this comment

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

string enum

@codecov
Copy link

codecov bot commented Nov 1, 2017

Codecov Report

Merging #336 into master will increase coverage by 0.22%.
The diff coverage is 99.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #336      +/-   ##
==========================================
+ Coverage    98.9%   99.13%   +0.22%     
==========================================
  Files          24       24              
  Lines        1740     1845     +105     
  Branches      462      467       +5     
==========================================
+ Hits         1721     1829     +108     
+ Misses          1        0       -1     
+ Partials       18       16       -2
Impacted Files Coverage Δ
src/splitpane/SplitPane.ts 98.57% <100%> (+0.13%) ⬆️
src/tabcontroller/TabController.ts 98.09% <100%> (+0.01%) ⬆️
src/dialog/Dialog.ts 97.67% <100%> (-0.06%) ⬇️
src/calendar/DatePicker.ts 99.27% <100%> (+0.06%) ⬆️
src/calendar/Calendar.ts 99.46% <100%> (+0.03%) ⬆️
src/radio/Radio.ts 98.27% <100%> (+0.23%) ⬆️
src/button/Button.ts 100% <100%> (ø) ⬆️
src/slider/Slider.ts 98.78% <100%> (+0.29%) ⬆️
src/calendar/CalendarCell.ts 100% <100%> (ø) ⬆️
src/tabcontroller/TabButton.ts 100% <100%> (ø) ⬆️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d33c943...aba806b. Read the comment docs.

@codecov
Copy link

codecov bot commented Nov 1, 2017

Codecov Report

Merging #336 into master will increase coverage by 0.12%.
The diff coverage is 99.68%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #336      +/-   ##
==========================================
+ Coverage    98.9%   99.03%   +0.12%     
==========================================
  Files          24       24              
  Lines        1740     1866     +126     
  Branches      462      480      +18     
==========================================
+ Hits         1721     1848     +127     
+ Misses          1        0       -1     
  Partials       18       18
Impacted Files Coverage Δ
src/calendar/Calendar.ts 99.46% <100%> (+0.03%) ⬆️
src/calendar/CalendarCell.ts 100% <100%> (ø) ⬆️
src/button/Button.ts 100% <100%> (ø) ⬆️
src/textinput/TextInput.ts 100% <100%> (ø) ⬆️
src/slider/Slider.ts 98.78% <100%> (+0.29%) ⬆️
src/tabcontroller/TabController.ts 98.09% <100%> (+0.01%) ⬆️
src/dialog/Dialog.ts 98.07% <100%> (+0.34%) ⬆️
src/checkbox/Checkbox.ts 98.59% <100%> (+0.15%) ⬆️
src/timepicker/TimePicker.ts 100% <100%> (ø) ⬆️
src/titlepane/TitlePane.ts 98.33% <100%> (+0.18%) ⬆️
... and 6 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d33c943...570dcc7. Read the comment docs.

Copy link
Contributor

@pottedmeat pottedmeat left a comment

Choose a reason for hiding this comment

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

Other than minor stuff, I think these new methods should have return types.

@@ -70,6 +70,30 @@ export default class Button extends ButtonBase<ButtonProperties> {
private _onTouchEnd (event: TouchEvent) { this.properties.onTouchEnd && this.properties.onTouchEnd(event); }
private _onTouchCancel (event: TouchEvent) { this.properties.onTouchCancel && this.properties.onTouchCancel(event); }

protected getContent() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we specify return types for these utility functions?

const { renderWeekdayCell } = this.properties;
return renderWeekdayCell ? renderWeekdayCell(day) : v('abbr', { title: day.long }, [ day.short ]);
protected renderDateCell(date: number, selected: boolean, currentMonth: boolean, today: boolean): DNode {
const key = currentMonth ? `date-${date}` : `date-${date}-dimmed`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should more/all the calculated values be extracted to the calling method?

Copy link
Contributor

Choose a reason for hiding this comment

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

This matches up with the comment on the unit test where key could be passed here so the renderDateCell override doesn't need to care about how to come up with its own unique key

'aria-haspopup': 'true',
id: `${this._idBase}_${type}_button`,
classes: this.classes(
(css as any)[`${type}Trigger`],
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to make this type safe, but I couldn't come up with a good solution that wouldn't add a ton of code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I chose concise code over css types in this particular case, but I was kinda ambivalent about it.

}

private _onNativeBlur(event: FocusEvent) {
this.properties.onBlur && this.properties.onBlur((<HTMLInputElement> event.target).value);
Copy link
Contributor

Choose a reason for hiding this comment

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

You could add this interface and use this instead of FocusEvent to clean things up a little.

interface FocusInputEvent extends FocusEvent {
	target: HTMLInputElement;
}

role: 'heading'
}, [
v('div', {
v('button', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this change to a button?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I always thought it should be a button, since one of the basic a11y principles in our widget design is to use native elements whenever possible. I just took this widget pattern PR as a good place to change it. It also simplifies the code a ton, since we no longer need to handle focus and key events manually.

}, [
v('i', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't this displayed anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is, I just moved it to this.renderExpandIcon()

@smhigley smhigley merged commit bae1322 into dojo:master Nov 1, 2017
@dylans dylans added this to the 2017.11 milestone Nov 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants