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

fix(api, class): remove ‘[class]’ selector #394

Merged
merged 1 commit into from
Sep 7, 2017

Conversation

ThomasBurleson
Copy link
Contributor

@ThomasBurleson ThomasBurleson commented Aug 28, 2017

The host class attribute should be considered static and should not be used as a ClassDirective selector. This means that without associated responsive APIs, the ClassDirective will not be instantiated for elements using only the class attribute.

  • Use the class attribute as a responsive fallback value only.
  • Improve support of the ngClass directive for string and object assignments.

Fixes #393.

@ThomasBurleson
Copy link
Contributor Author

@crisbeto - would you mind reviewing this one ?

Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

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

LGTM, a few nits.

* Does this directive have 1 or more responsive keys defined
* Note: we exclude the 'baseKey' key (which is NOT considered responsive)
*/
public get usesResponsiveAPI() {
Copy link
Member

Choose a reason for hiding this comment

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

Something like this might be more concise:

public get usesResponsiveAPI() {
  const numKeys = Object.keys(this._inputMap).length;
  return !!(numKeys === 1 || !this._inputMap[this._baseKey]);
}

Copy link
Contributor Author

@ThomasBurleson ThomasBurleson Sep 3, 2017

Choose a reason for hiding this comment

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

@crisbeto - that logic is not correct since we are checking for 1 or more non-baseKey values.

public get usesResponsiveAPI() {
    const totalKeys = Object.keys(this._inputMap).length; 
    const baseValue = this._inputMap[this._baseKey];
    return  (totalKeys - (!!baseValue ? 1 : 0)) > 0;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -130,7 +134,7 @@ export abstract class BaseFxDirective implements OnDestroy, OnChanges {
* and optional restore it when the mediaQueries deactivate
*/
protected _getDisplayStyle(source?: HTMLElement): string {
let element: HTMLElement = source || this._elementRef.nativeElement;
let element: HTMLElement = source || this.nativeElement;
Copy link
Member

Choose a reason for hiding this comment

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

Consider switching the method signature to source = this.nativeElement here and in _applyStyleToElement.

@Input('class.gt-xs') set classGtXs(val: NgClassType) { this._classAdapter.cacheInput('classGtXs', val); }
@Input('class.gt-sm') set classGtSm(val: NgClassType) { this._classAdapter.cacheInput('classGtSm', val); }
@Input('class.gt-md') set classGtMd(val: NgClassType) { this._classAdapter.cacheInput('classGtMd', val); }
@Input('class.gt-lg') set classGtLg(val: NgClassType) { this._classAdapter.cacheInput('classGtLg', val); }
Copy link
Member

Choose a reason for hiding this comment

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

All of these setters will generate a lot of ES5 JS. Have you considered using ngOnChanges and looping through the changed inputs to cache them instead?

Choose a reason for hiding this comment

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

@crisbeto was this addressed before merge?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@crisbeto - there is a PR for this ^ feature in @angular: angular/angular#13355

@@ -142,7 +142,7 @@ export class LayoutWrapDirective extends BaseFxDirective implements OnInit, OnCh
}

protected get flowDirection(): string {
let computeFlowDirection = () => this._getFlowDirection(this._elementRef.nativeElement);
let computeFlowDirection = () => this._getFlowDirection(this.nativeElement);
return this._layoutWatcher ? this._layout : computeFlowDirection();
Copy link
Member

Choose a reason for hiding this comment

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

Defining a function just to call it immediately seems a little wasteful. Consider returning this._getFlowDirection(this.nativeElement) instead?

@crisbeto crisbeto added pr: lgtm This PR has been approved by the reviewer pr: merge ready This PR is ready for the caretaker to presubmit and merge labels Aug 29, 2017
The host `class` attribute should be considered static and should not be used as a ClassDirective selector.

This means that without associated responsive APIs,
the ClassDirective will not be instantiated for elements using only the `class` attribute.

* Use the `class` attribute as a responsive fallback value only.
* Improve support of the ngClass directive for string and object assignments.

Fixes #393.
@tinayuangao tinayuangao merged commit 7a48c25 into master Sep 7, 2017
@ThomasBurleson ThomasBurleson deleted the thomas/issue-393 branch September 13, 2017 22:12
@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 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes pr: lgtm This PR has been approved by the reviewer pr: merge ready This PR is ready for the caretaker to presubmit and merge pr: needs presubmit (3rd)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'ngDoCheck' of null
5 participants