This repository was archived by the owner on Jan 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 764
fix(api): defer getComputedStyle() calls until ngOnInit phase #374
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
import {Component} from '@angular/core'; | ||
import {CommonModule} from '@angular/common'; | ||
import {TestBed} from '@angular/core/testing'; | ||
|
||
import {customMatchers} from './testing/custom-matchers'; | ||
import {makeExpectDOMFrom} from './testing/helpers'; | ||
|
||
describe('style-utils directive', () => { | ||
let expectDOMFrom = makeExpectDOMFrom(() => TestLayoutComponent); | ||
|
||
beforeEach(() => { | ||
jasmine.addMatchers(customMatchers); | ||
|
||
// Configure testbed to prepare services | ||
TestBed.configureTestingModule({ | ||
imports: [CommonModule], | ||
declarations: [TestLayoutComponent] | ||
}); | ||
}); | ||
|
||
describe('testing display styles', () => { | ||
|
||
it('should default to "display:block" for <div></div>', () => { | ||
expectDOMFrom(` | ||
<div></div> | ||
`).toHaveStyle({'display': 'block'}); | ||
}); | ||
|
||
it('should find to "display" for inline style <div></div>', () => { | ||
expectDOMFrom(` | ||
<div style="display: flex;"></div> | ||
`).toHaveStyle({'display': 'flex'}); | ||
}); | ||
|
||
it('should find `display` from html style element', () => { | ||
expectDOMFrom(` | ||
<style> | ||
div.special { display: inline-block; } | ||
</style> | ||
<div class="special"></div> | ||
`).toHaveStyle({'display': 'inline-block'}); | ||
}); | ||
|
||
it('should find `display` from component styles', () => { | ||
let expectStyledDOM = makeExpectDOMFrom(() => TestLayoutComponent, [ | ||
'div.extra { display:table; }' | ||
]); | ||
expectStyledDOM(` | ||
<div class="extra"></div> | ||
`).toHaveStyle({'display': 'table'}); | ||
}); | ||
|
||
}); | ||
|
||
|
||
}); | ||
|
||
|
||
// ***************************************************************** | ||
// Template Component | ||
// ***************************************************************** | ||
|
||
@Component({ | ||
selector: 'test-style-utils', | ||
template: `<span>PlaceHolder Template HTML</span>` | ||
}) | ||
export class TestLayoutComponent { | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
hasInitialized
is only used in angDoCheck
hook. According to this chart, it shouldn't be possible forngDoCheck
to fire beforengOnInit
, making the flag redundant.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.
Not sure what you mean. Many of the directives using
ngOnInit()
, the hasInitialized() is a custom method used in the Flex directives.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 mean that the only place I see it being used is https://github.com/angular/flex-layout/pull/374/files#diff-5bc48b81f8309cb16bb22da0a329e466R140 which shouldn't be possible to fire before
ngOnInit
. I might be missing some context here, though.Uh oh!
There was an error while loading. Please reload this page.
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 correct that
ShowHideDirective::ngOnChanges()
usesthis.hasInitialized
.ngOnChanges()
is called 1x before ngOnInit() and then later when the @input values are externally changed. The intention of that logic is to SKIP any responses to changes until afterngOnInit()
.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.
Alright, makes sense. I suppose it also depends on the component tree.