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

Cleanup #274

Merged
merged 5 commits into from Jan 14, 2018
Merged

Cleanup #274

merged 5 commits into from Jan 14, 2018

Conversation

rimlin
Copy link
Collaborator

@rimlin rimlin commented Jan 9, 2018

#270
Tasks 2, 4, 5

Copy link
Owner

@tjoskar tjoskar left a 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() {
Copy link
Owner

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()?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I vote for isWindowDefined() 👍


const windowTarget = typeof window !== 'undefined' ? window : undefined;
const windowTarget = isWindowExists() ? window : undefined;
Copy link
Owner

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.

*/
if (typeof window === 'undefined') {
if (isWindowExists() === false) {
Copy link
Owner

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()?

Copy link
Collaborator Author

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, '');
Copy link
Owner

@tjoskar tjoskar Jan 9, 2018

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

Copy link
Owner

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.

@@ -4,6 +4,8 @@ import 'rxjs/add/operator/share';
import 'rxjs/add/observable/empty';
import { Observable } from 'rxjs/Observable';

import { isWindowExists } from './utils';
Copy link
Owner

@tjoskar tjoskar Jan 9, 2018

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',
}
Copy link
Owner

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?

@tjoskar tjoskar merged commit 2907c13 into tjoskar:master Jan 14, 2018
@tjoskar
Copy link
Owner

tjoskar commented Jan 14, 2018

Thanks @rimlin

@tjoskar tjoskar mentioned this pull request Jan 14, 2018
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants