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
Cleanup #274
Cleanup #274
Conversation
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.
Thanks @rimlin!
Take a look at my comments and say what you think.
src/utils.ts
Outdated
@@ -0,0 +1,9 @@ | |||
export function isWindowExists() { |
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'm not sure about the name :) What do you think of isWindowDefined()
or isBrowserContext()
?
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 vote for isWindowDefined()
👍
src/lazyload-image.directive.ts
Outdated
|
||
const windowTarget = typeof window !== 'undefined' ? window : undefined; | ||
const windowTarget = isWindowExists() ? window : undefined; |
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 think it is better to move down this line to where it is used (~82), now when it is so simple.
src/lazyload-image.directive.ts
Outdated
*/ | ||
if (typeof window === 'undefined') { | ||
if (isWindowExists() === false) { |
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.
Why checking against false
and not just: !isWindowExists()
?
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 was prefer it, because this approach is more explicit as i think, but if it not acceptable - no problem
if (element.className && element.className.includes('ng-lazyloaded')) { | ||
element.className = element.className.replace('ng-lazyloaded', ''); | ||
if (element.className && element.className.includes(cssClassNames.loaded)) { | ||
element.className = element.className.replace(cssClassNames.loaded, ''); |
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 much better but I still think that we should create a function that is only responsible for setting and removing css class names. Something like:
function removeCssClassName(element: HTMLImageElement | HTMLDivElement, cssClassName: string) {
element.className = element.className.replace(cssClassName, '');
}
function addCssClassName(element: HTMLImageElement | HTMLDivElement, cssClassName: string) {
if (!element.className.includes(cssClassName)) {
element.className += ` ${cssClassName}`
}
}
And then use these two function instead of:
if (element.className && element.className.includes(cssClassNames.loaded)) {
element.className = element.className.replace(cssClassNames.loaded, '');
}
element.className += ' ' + cssClassNames.failed;
setLoadedStyle
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.
@rimlin, I saw your comment now, regarding that you addressed 2, 4, 5 and not 3 which this comment is about. I will therefore accept this PR without this change.
src/scroll-listener.ts
Outdated
@@ -4,6 +4,8 @@ import 'rxjs/add/operator/share'; | |||
import 'rxjs/add/observable/empty'; | |||
import { Observable } from 'rxjs/Observable'; | |||
|
|||
import { isWindowExists } from './utils'; |
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 there an extra white line above import { isWindowExists } from './utils';
? Can you remove it :)
src/utils.ts
Outdated
loaded: 'ng-lazyloaded', | ||
loading: 'ng-lazyloading', | ||
failed: 'ng-failed-lazyloaded', | ||
} |
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.
What do you think of creating a new file, calling constants and place cssClassNames
inside it?
Thanks @rimlin |
#270
Tasks 2, 4, 5