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

feat: add ability to configure lazy loading #147

Merged
merged 1 commit into from
Oct 25, 2018
Merged

Conversation

rostik404
Copy link
Collaborator

No description provided.

@@ -58,6 +58,11 @@ class ControlButtons extends Component {
isActive={view.scaleImages}
handler={actions.toggleScaleImages}
/>
<ControlButton
label="Lazy load"
Copy link
Member

Choose a reason for hiding this comment

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

я бы тут добавил именно 'Lazy image load'

Copy link
Member

Choose a reason for hiding this comment

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

А я бы назвал Lazy image loading

/>
</LazyLoad>
);
const elem = <img
Copy link
Member

Choose a reason for hiding this comment

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

давай в одну строку - тут же кода понты

@@ -13,7 +13,8 @@ export default {
config: {
defaultView: 'all',
scaleImages: false,
baseHost: ''
baseHost: '',
lazyLoadOffset: 800
Copy link
Member

Choose a reason for hiding this comment

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

какая-то у нас тут херь происходит - получается, что у нас дефолты указываются в двух местах (в конфиге плагина и здесь)

Copy link
Member

Choose a reason for hiding this comment

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

Согласен, полная херня. Должен быть один источник правды

@sipayRT
Copy link
Member

sipayRT commented Oct 23, 2018

кстати, а тесты то где? :)
на реактовский компонент напиши типа https://github.com/gemini-testing/html-reporter/blob/master/test/lib/static/components/section/state.js#L79

Copy link
Member

@DudaGod DudaGod left a comment

Choose a reason for hiding this comment

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

Мне не нравится, что в итоге у нас есть 2 опции lazyLoad и lazyLoadOffset. Почему не достаточно сделать одну опцию? Плюс из конфига никак нельзя вообще отключить lazyLoad. Он всегда выставлен в true по умолчанию. Можно было бы при клике на кнопку Lazy load выставлять lazyLoadOffset в ноль.

README.md Outdated
@@ -23,6 +23,7 @@ directory.
* `failed` - show only failed tests.
* **baseHost** (optional) - `String` - it changes original host for view in the browser; by default original host does not change
* **scaleImages** (optional) – `Boolean` – fit images into page width; `false` by default
* **lazyLoadOffset** (optional) - `Number` - allows you to specify how far above and below the viewport you want to begin loading images
Copy link
Member

Choose a reason for hiding this comment

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

значение по умолчанию не указал

Copy link
Member

Choose a reason for hiding this comment

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

Может сделаем вложенность небольшую?

lazyLoad: {
  enabled: true,
  offset: 100500
}

lib/config.js Outdated
@@ -45,6 +46,10 @@ const getParser = () => {
parseEnv: JSON.parse,
parseCli: JSON.parse,
validate: assertBoolean('scaleImages')
}),
lazyLoadOffset: option({
defaultValue: 800,
Copy link
Member

Choose a reason for hiding this comment

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

кажется пора заводить отдельный файл с значениями по умолчанию

@@ -58,6 +58,11 @@ class ControlButtons extends Component {
isActive={view.scaleImages}
handler={actions.toggleScaleImages}
/>
<ControlButton
label="Lazy load"
Copy link
Member

Choose a reason for hiding this comment

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

А я бы назвал Lazy image loading

@@ -13,7 +13,8 @@ export default {
config: {
defaultView: 'all',
scaleImages: false,
baseHost: ''
baseHost: '',
lazyLoadOffset: 800
Copy link
Member

Choose a reason for hiding this comment

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

Согласен, полная херня. Должен быть один источник правды

scaleImages: PropTypes.bool
scaleImages: PropTypes.bool,
lazyLoad: PropTypes.bool,
lazyLoadOffset: PropTypes.number
Copy link
Member

Choose a reason for hiding this comment

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

не понял этот дифф. Ты же эти поля из стейта тут не достаешь и никак не используешь

);
}

return elem;
Copy link
Member

Choose a reason for hiding this comment

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

давай через тернарник напишем, красивее же будет

}
}

export default connect(({view: {lazyLoad, lazyLoadOffset}}) => ({lazyLoad, lazyLoadOffset}))(Screenshot);
Copy link
Member

Choose a reason for hiding this comment

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

у тебя lazyLoadOffset должен браться из config, а не из view

@@ -20,5 +20,6 @@ export default {
VIEW_TOGGLE_SKIPPED: 'VIEW_TOGGLE_SKIPPED',
VIEW_TOGGLE_ONLY_DIFF: 'VIEW_TOGGLE_ONLY_DIFF',
VIEW_UPDATE_BASE_HOST: 'VIEW_UPDATE_BASE_HOST',
VIEW_TOGGLE_SCALE_IMAGES: 'VIEW_TOGGLE_SCALE_IMAGES'
VIEW_TOGGLE_SCALE_IMAGES: 'VIEW_TOGGLE_SCALE_IMAGES',
VIEW_TOGGLE_LAZY_LOAD: 'VIEW_TOGGLE_LAZY_LOAD'
Copy link
Member

Choose a reason for hiding this comment

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

я бы тут images тоже добавил бы

@@ -22,6 +22,7 @@ function getInitialState(compiledData) {
view: {
viewMode: config.defaultView,
scaleImages: config.scaleImages,
lazyLoadOffset: config.lazyLoadOffset,
Copy link
Member

Choose a reason for hiding this comment

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

а для чего так делать? В компоненте screenshot бери это значение просто из config. К view же это не относится. К нему относится только lazyLoad

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

После того, как реализовал через одну опцию, это стало необходимо выгружать во view, т.к. это уже не просто константа.

const formattedSuites = formatSuitesData(suites);

return merge({}, state, {gui, autoRun, skips, view: {scaleImages}}, formattedSuites);
return merge({}, state, {gui, autoRun, skips, view: {scaleImages, lazyLoadOffset}}, formattedSuites);
Copy link
Member

Choose a reason for hiding this comment

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

а lazyLoad куда потерял? Ты же его тоже должен прокинуть.
Плюс очень путает, что ты взял значение из конфига и прокинул его во view. Хотя тебе это делать вообще не нужно

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

уже не актуально

@sipayRT
Copy link
Member

sipayRT commented Oct 24, 2018

идея с одним параметром норм

Copy link
Member

@sipayRT sipayRT left a comment

Choose a reason for hiding this comment

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

в остальном ок

@@ -136,4 +136,30 @@ describe('config', () => {
assert.isTrue(parseConfig({}).scaleImages);
});
});

describe('"lazyLoadOffset" option', () => {
it('should has default balue', () => {
Copy link
Member

Choose a reason for hiding this comment

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

⚠️ balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue, balue ⚠️


describe('"lazyLoadOffset" option', () => {
it('should has default balue', () => {
assert.equal(parseConfig({}).lazyLoadOffset, 800);
Copy link
Member

Choose a reason for hiding this comment

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

вместо 800 укажи значение из дефолтов

@@ -136,4 +136,30 @@ describe('config', () => {
assert.isTrue(parseConfig({}).scaleImages);
});
});

describe('"lazyLoadOffset" option', () => {
Copy link
Member

Choose a reason for hiding this comment

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

добавь тест на то, что можно предавать только числа

assert.lengthOf(lazyLoadContainer, 0);
});

it('should not load images lazy of lazy load offset is not specified', () => {
Copy link
Member

Choose a reason for hiding this comment

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

этот тест у тебя сейчас ничем не отличается от предыдущего

@rostik404 rostik404 merged commit ada7628 into master Oct 25, 2018
@rostik404 rostik404 deleted the fix-lazy-load branch October 25, 2018 09:27
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.

3 participants