-
Notifications
You must be signed in to change notification settings - Fork 772
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(ngClass,ngStyle): support proper API usages and ChangeDetectionStrategy.OnPush strategies #228
Conversation
c0cb733
to
cf60c0a
Compare
src/lib/flexbox/api/base-adapter.ts
Outdated
|
||
/** | ||
* Adapter to the BaseFxDirective abstract class so it can be used via composition. | ||
* @see BaseFxDirective | ||
*/ | ||
export class BaseFxDirectiveAdapter extends BaseFxDirective { | ||
|
||
get activeKey() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a description comment
src/lib/flexbox/api/base-adapter.ts
Outdated
@@ -19,10 +38,21 @@ export class BaseFxDirectiveAdapter extends BaseFxDirective { | |||
} | |||
|
|||
/** | |||
* | |||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty comment block?
src/lib/flexbox/api/base-adapter.ts
Outdated
@@ -19,10 +38,21 @@ export class BaseFxDirectiveAdapter extends BaseFxDirective { | |||
} | |||
|
|||
/** | |||
* | |||
*/ | |||
constructor(protected _baseKey: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
baseKey
needs a description comment (as a class member) since it's non-obvious
src/lib/flexbox/api/base.ts
Outdated
* Dictionary of input keys with associated values | ||
*/ | ||
protected _inputMap = {}; | ||
get hasMQListener() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hasMediaQueryListener
?
src/lib/flexbox/api/base.ts
Outdated
this._mqActivation = new ResponsiveActivation( | ||
keyOptions, | ||
this._mediaMonitor, | ||
(change) => onMediaQueryChange.call(this, change) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(change) => this.onMediaQueryChange(change)
(there's no need for .call
here)
src/lib/flexbox/api/base.ts
Outdated
@@ -201,4 +195,18 @@ export abstract class BaseFxDirective implements OnDestroy { | |||
return this._mqActivation.hasKeyValue(key); | |||
} | |||
|
|||
/** | |||
* Original dom Elements CSS display style | |||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can collapse short description blocks into a single line:
/** The element's original CSS `display` property value. */
src/lib/flexbox/api/class.ts
Outdated
_iterableDiffers: IterableDiffers, _keyValueDiffers: KeyValueDiffers, | ||
_ngEl: ElementRef, _renderer: Renderer) { | ||
super(_iterableDiffers, _keyValueDiffers, _ngEl, _renderer); | ||
this._base = new BaseFxDirectiveAdapter(monitor, _ngEl, _renderer); | ||
this._base = new BaseFxDirectiveAdapter("class", monitor, _ngEl, _renderer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Single quotes (there should be a lint check for this)
src/lib/flexbox/api/class.ts
Outdated
@@ -72,7 +69,7 @@ export class ClassDirective extends NgClass implements OnInit, OnChanges, OnDest | |||
@Input('ngClass.gt-lg') set ngClassGtLg(val: NgClassType) { this._base.cacheInput('classGtLg', val, true); }; | |||
|
|||
/** Deprecated selectors */ | |||
@Input('class') set classBase(val: NgClassType) { this._base.cacheInput('class', val, true); } | |||
@Input('class') set klazz(val: NgClassType) { this._base.cacheInput('class', val, true); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cssClass
would be a lot more descriptive than klazz
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a similar convention used by NgClass:
@Input('class')
set klass(v: string) { ... }
src/lib/flexbox/api/class.ts
Outdated
if (changed || this._base.mqActivation) { | ||
this._updateClass(); | ||
const changed = (this._base.activeKey in changes); | ||
return changed && this._updateClass(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Angular does not do anything with the return value of lifecycle events
2c67ed4
to
40a33b1
Compare
@jelbourn - comments addressed. Ready for presubmit. |
95bb161
to
d2517b8
Compare
@jelbourn - I will remove support for |
d2517b8
to
72afd0c
Compare
167cb8c
to
9c425aa
Compare
@jelbourn - ready for review and presubmit. All tests pass.
|
9c425aa
to
7bb2d96
Compare
@mmalerba - can you review these fixes ? Thanks. |
7bb2d96
to
1bf533b
Compare
src/lib/flexbox/api/class.ts
Outdated
@Input('ngClass.lg') set ngClassLg(val: NgClassType) { this._ngClassAdapter.cacheInput('ngClassLg', val, true);}; | ||
@Input('ngClass.xl') set ngClassXl(val: NgClassType) { this._ngClassAdapter.cacheInput('ngClassXl', val, true); }; | ||
|
||
@Input('ngClass.lt-xs') set ngClassLtXs(val: NgClassType) { this._ngClassAdapter.cacheInput('ngClassLtXs', val, true); }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is lt-xs
a real thing? I think this should be lt-xl
* e.g. which property value will be used. | ||
*/ | ||
get activeKey() { | ||
let mqa = this._mqActivation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems pointless? just use _mqActivation below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a short-cut reference to keep the code clean.
src/lib/flexbox/api/base-adapter.ts
Outdated
let key = mqa ? mqa.activatedInputKey : this._baseKey; | ||
// ClassDirective::SimpleChanges uses 'klazz' | ||
// instead of 'class' as a key | ||
return (key === 'class') ? 'klazz' : key; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to double check, this is really what you want right? I see klazz
, clazz
and klass
at various points in the code. Also future work: we should make this consistent everywhere, I vote for cssClass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
angular ng-class.ts
uses klass
. Since they already set a precedent, why not be consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok but is this the correct one? because I do see all three of these in the code. More important than what we decide to call it is that it be consistent within our code instead of having 3 different variants. But I don't think we necessarily have to follow the same naming conventions for internal variables as them, this is a totally separate repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ok I see this is referencing the one from angular core, no issue for this PR then, just the naming thing to consider in the future
src/lib/flexbox/api/class.ts
Outdated
@Input('class.lg') set classLg(val: NgClassType) { this._classAdapter.cacheInput('classLg', val, true); }; | ||
@Input('class.xl') set classXl(val: NgClassType) { this._classAdapter.cacheInput('classXl', val, true); }; | ||
|
||
@Input('class.lt-xs') set classLtXs(val: NgClassType) { this._classAdapter.cacheInput('classLtXs', val, true); }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be lt-xl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lt-xl
, lt-lg
, lt-md
,lt-sm
are all valid responsive aliases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see... the Inputs are not entirely correct. I will fix.
1bf533b
to
446fc8b
Compare
…rategy.OnPush strategies * fix(ngClass): properly differentiate between `ngClass` and `class` api usages * `class.<xxx>` are destructive overrides (as seen in `NgClass::klass`) * `ngClass.<xxx>` use iterables to merge/enable/disable 0...n classes * fix(ngClass,ngStyle): support ChangeDetectionStrategy.OnPush * Add support for both **OnPush** change detection strategies and for @input changes. * fix class lt-<xx> selectors > @see https://plnkr.co/edit/jCICQ1GXFnzFqFTFlXwh?p=preview fixes #206, fixes #215.
446fc8b
to
5c098d6
Compare
FYI - A design doc is being prepared to discuss the Responsive API for ngClass, class, ngStyle, and style. Future changes - based on the document - may be presented via 1 or more additional PRs. |
See more details here: angular/flex-layout#228
…rategy.OnPush strategies (angular#228) * fix(ngClass): properly differentiate between `ngClass` and `class` api usages * `class.<xxx>` are destructive overrides (as seen in `NgClass::klass`) * `ngClass.<xxx>` use iterables to merge/enable/disable 0...n classes * fix(ngClass,ngStyle): support ChangeDetectionStrategy.OnPush * Add support for both **OnPush** change detection strategies and for @input changes. * fix class lt-<xx> selectors > @see https://plnkr.co/edit/jCICQ1GXFnzFqFTFlXwh?p=preview fixes angular#206, fixes angular#215.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
ngClass
andclass
api usagesclass.<xxx>
are destructive overrides (as seen inNgClass::klass
)ngClass.<xxx>
use iterables to merge/enable/disable 0...n classesfixes #206, fixes #215.