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

feat: nullability support #5094

Merged
merged 2 commits into from Jun 21, 2017
Merged

Conversation

crisbeto
Copy link
Member

Adds compatibility with strictNullChecks to the library, tests, build and various test apps.

Fixes #3486.

@crisbeto crisbeto self-assigned this Jun 12, 2017
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jun 12, 2017
@@ -318,7 +318,7 @@ class SlideToggleRenderer {

/** Resets the current drag and returns the new checked value. */
stopThumbDrag(): boolean {
if (!this.dragging) { return; }
if (!this.dragging) { return this.dragging; }
Copy link
Member

Choose a reason for hiding this comment

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

Just a note for your wip: This is can be always return false

@crisbeto crisbeto force-pushed the strict-null-checks-redux branch 3 times, most recently from 7614fb6 to 62bd6f5 Compare June 12, 2017 20:59
@crisbeto crisbeto changed the title wip: feat: nullability support feat: nullability support Jun 12, 2017
@crisbeto crisbeto assigned jelbourn and unassigned crisbeto Jun 12, 2017
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

Looks good, just a handful of minor comments

@@ -65,13 +65,13 @@ export class MdButtonToggleGroup implements AfterViewInit, ControlValueAccessor
private _name: string = `md-button-toggle-group-${_uniqueIdCounter++}`;

/** Disables all toggles in the group. */
private _disabled: boolean = null;
private _disabled: boolean | null = null;
Copy link
Member

Choose a reason for hiding this comment

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

Why not default this to false?
(same for other boolean properties)

Copy link
Member Author

@crisbeto crisbeto Jun 13, 2017

Choose a reason for hiding this comment

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

EDIT: Just saw your comment below. I'll refactor the bindings to disabled || null.

It's because the disabled attribute needs to be removed from the DOM completely when enabled. We could also switch the bindings to be something like disabled || null.

if (month < 0 || month > 11 || date < 1) {
return null;
if (month < 0 || month > 11) {
throw new Error(`Invalid month index "${month}". Month index has to be between 0 and 11.`);
Copy link
Member

Choose a reason for hiding this comment

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

Can omit the new for Error (woo, 4 bytes)

}

if (date < 1) {
throw new Error(`Invalid date "${date}". Date has to be larger than 0.`);
Copy link
Member

Choose a reason for hiding this comment

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

"larger than" > "greater than"

@@ -94,7 +94,7 @@ export class ConnectedPositionStrategy implements PositionStrategy {
* @param element Element to which to apply the CSS styles.
* @returns Resolves when the styles have been applied.
*/
apply(element: HTMLElement): Promise<void> {
apply(element: HTMLElement): Promise<null> {
Copy link
Member

Choose a reason for hiding this comment

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

Can we work around this by having a custom type declaration to overload resolve such that resolve(): Promise<void>?

Promise<null> => (╯°□°)╯︵ ┻━┻

(alternatively, apply is and always has been synchronous, so we could just take the promise away)

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what that would look like, null | undefined? Otherwise I'm in favor of removing the promise completely, although I could see it being useful if we decide to introduce animations into the overlays.

viewContainerRef: ViewContainerRef = null,
injector: Injector = null) {
viewContainerRef?: ViewContainerRef,
injector?: Injector) {
Copy link
Member

Choose a reason for hiding this comment

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

Could make these | null just to be more lenient (anywhere with multiple optional params where you might want to pass a latter one but an earlier one)

Copy link
Member Author

Choose a reason for hiding this comment

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

I went with optionals here, because they were marked as [Optional] a little bit up in the doc strings for the properties.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I accidentally omitted the word "also". Meant that we could do
viewContainerRef?: ViewContainerRef | null, so that either undefined or null can be passed in cases when you don't care for that argument.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense. Added.

let viewportRuler: ViewportRuler;

/** Extracts the numeric value of a pixel size string like '123px'. */
const pxStringToFloat = (s: string | null) => s ? parseFloat(s.replace('px', '')) : 0;
Copy link
Member

Choose a reason for hiding this comment

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

I know it was already like this, but doesn't parseFloat already ignore trailing non-numeric characters already?

Copy link
Member Author

Choose a reason for hiding this comment

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

It does. This can be changed to parseFloat(...) || 0.


expect(() => dialogRef = dialog.open(DialogWithInjectedData)).not.toThrow();
expect(dialogRef.componentInstance.data).toBeNull();
// TODO: double check that this does what i expect
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ops, forgot to follow up on this one. I wanted to check that the expect inside the expect.not.toThrow won't cause any issues. I'll check it and refactor or remove the todo.

* @docs-private
*/
export function getMdIconFailedToSanitizeError(url: SafeResourceUrl): Error {
return new Error(`MdIconRegistry has failed to sanitize the following URL: ${url}.`);
Copy link
Member

Choose a reason for hiding this comment

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

A more accurate error message would be something like "The url provided to MdIconRegistry was not trusted as a resource URL via Angular's DomSanitizer"

@@ -44,7 +44,7 @@ export class MdMenuItem implements Focusable {
}

/** Used to set the HTML `disabled` attribute. Necessary for links to be disabled properly. */
_getDisabledAttr(): boolean {
_getDisabledAttr(): true | null {
Copy link
Member

Choose a reason for hiding this comment

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

I'm a fan of doing disabled || null in the host binding

This means that the attribute is correctly removed in the DOM but programmatic APIs return the expected true/false

@crisbeto crisbeto force-pushed the strict-null-checks-redux branch 3 times, most recently from c1c7dcd to 5e9b13e Compare June 13, 2017 18:59
@crisbeto
Copy link
Member Author

Rebased and addressed the feedback @jelbourn.

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Jun 13, 2017
@crisbeto crisbeto force-pushed the strict-null-checks-redux branch 2 times, most recently from 08da2d8 to ced3171 Compare June 13, 2017 21:39
@kara kara added presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged pr: needs rebase labels Jun 13, 2017
@kara kara added pr: needs rebase and removed action: merge The PR is ready for merge by the caretaker labels Jun 16, 2017
@kara kara assigned crisbeto and unassigned jelbourn Jun 16, 2017
@kara
Copy link
Contributor

kara commented Jun 16, 2017

@crisbeto This one needs rebase too, when you get a chance.

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed pr: needs rebase labels Jun 17, 2017
@jelbourn
Copy link
Member

I rebased it (was trivial)

crisbeto and others added 2 commits June 20, 2017 15:46
Adds compatibility with strictNullChecks to the library, tests, build and various test apps.

Fixes angular#3486.
@jelbourn jelbourn removed the presubmit failures This PR has failures in Google's internal presubmit process and cannot be immediately merged label Jun 21, 2017
@jelbourn jelbourn merged commit 2bf7024 into angular:master Jun 21, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants