-
Notifications
You must be signed in to change notification settings - Fork 771
fix(api): use only Renderer2 instances #391
Conversation
@jelbourn - ready for your review also. |
@crisbeto - would you mind reviewing this one ? |
src/lib/api/core/renderer-adapter.ts
Outdated
// we only use setElementStyle() and setElementClass() | ||
// ****************************************************************** | ||
|
||
selectRootElement(): any { } |
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.
If these methods aren't meant to be used, consider throwing an error or removing the implementation so they fall back to the inherited ones from the 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.
We cannot remove the implementation... We want to to appear as a Renderer1 instance but built from a Renderer2. Renderer is an abstract class with many abstract methods. This is we have to implement them EVEN if ignored.
But we can throw error as not-implemented!
Fixed.
* Curried value to function to check styles that are inline or in a stylesheet for the | ||
* specified DOM element. | ||
*/ | ||
function buildCompareStyleFunction(inlineOnly = 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.
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 because PR 391 will be rebased after #390 gets merged.
src/lib/utils/testing/dom-tools.ts
Outdated
@@ -73,6 +76,14 @@ function hasClass(element: any, className: string): boolean { | |||
return element.classList.contains(className); | |||
} | |||
|
|||
function hasAttribute(element: any, attributeName: string): boolean { | |||
return element.hasAttribute(attributeName); |
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.
It doesn't look like most of these DOM utilities are doing much, aside from proxying the native functions with the exact same arguments.
ce7d828
to
cc542d1
Compare
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.
LGTM
@ThomasBurleson ping me when this one is rebased |
cc542d1
to
392545e
Compare
src/lib/api/core/renderer-adapter.ts
Outdated
* This is required for older versions of NgStyle and NgClass: which require | ||
* the v1 API (but should use the v2 instances) | ||
*/ | ||
export class RendererAdapter extends 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.
You are still referring to Renderer
. I think you should drop that.
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.
@mhevery - To manually construct a NgClass I must pass it an instance of a class that extends Renderer
. Or am I missing something ?
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.
Do you mean change RendererAdapter
to HybridAdapter
?
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.
The whole point of the issue is that the Renderer
symbol is being removed entirely.
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.
@jelbourn -If we do this, then we break support for Angular 4.x
// Create an instance NgClass Directive instance only if `ngClass=""` has NOT been defined on
// the same host element; since the responsive variations may be defined...
if ( !this._ngClassInstance ) {
let adapter = new RendererAdapter(_renderer);
this._ngClassInstance = new NgClass(_iterableDiffers, _keyValueDiffers, _ngEl, adapter);
}
since NgClass in core (v4.3) expects a Renderer subclass.
export declare abstract class 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.
So I am not sure WHAT to do here because the darn Renderer
extends an abstract base class instead of implementing an interface.
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.
Instead of creating an internal ngClass instance, I could just copy the class implementation methods from ngClass (in core), but that seems to be a clumsy solution. Perhaps that is the only viable solution ?
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.
- don't implement
Renderer
- Make sure that the Shape of the classes matches what
Renderer
expects (this should be noop since you implemented it.) - When passing it into
NgClass
just cast it toany
so that the compiler is happy.
392545e
to
c175adb
Compare
@mhevery - Imports of export class RendererAdapter { }
// ...
if ( !this._ngClassInstance ) {
let adapter = new RendererAdapter(_renderer);
this._ngClassInstance = new NgClass(_iterableDiffers, _keyValueDiffers, _ngEl, <any> adapter);
}
|
Perfect LGTM |
@jelbourn Ping! :) Would be cool if we could get this in and release as |
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 and NgStyle use Renderer1 instances; which has been deprecated. Instead use Renderer2 and a RendererAdapter.
Thx @mhevery for his solution!
Refs #386. Fixes #398, #408.