-
Notifications
You must be signed in to change notification settings - Fork 39
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
Conversation
@@ -58,6 +58,11 @@ class ControlButtons extends Component { | |||
isActive={view.scaleImages} | |||
handler={actions.toggleScaleImages} | |||
/> | |||
<ControlButton | |||
label="Lazy load" |
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.
я бы тут добавил именно 'Lazy image load'
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.
А я бы назвал Lazy image loading
/> | ||
</LazyLoad> | ||
); | ||
const elem = <img |
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.
давай в одну строку - тут же кода понты
lib/static/modules/default-state.js
Outdated
@@ -13,7 +13,8 @@ export default { | |||
config: { | |||
defaultView: 'all', | |||
scaleImages: false, | |||
baseHost: '' | |||
baseHost: '', | |||
lazyLoadOffset: 800 |
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.
Согласен, полная херня. Должен быть один источник правды
кстати, а тесты то где? :) |
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.
Мне не нравится, что в итоге у нас есть 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 |
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.
Может сделаем вложенность небольшую?
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, |
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.
кажется пора заводить отдельный файл с значениями по умолчанию
@@ -58,6 +58,11 @@ class ControlButtons extends Component { | |||
isActive={view.scaleImages} | |||
handler={actions.toggleScaleImages} | |||
/> | |||
<ControlButton | |||
label="Lazy load" |
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.
А я бы назвал Lazy image loading
lib/static/modules/default-state.js
Outdated
@@ -13,7 +13,8 @@ export default { | |||
config: { | |||
defaultView: 'all', | |||
scaleImages: false, | |||
baseHost: '' | |||
baseHost: '', | |||
lazyLoadOffset: 800 |
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.
Согласен, полная херня. Должен быть один источник правды
lib/static/components/state/index.js
Outdated
scaleImages: PropTypes.bool | ||
scaleImages: PropTypes.bool, | ||
lazyLoad: PropTypes.bool, | ||
lazyLoadOffset: PropTypes.number |
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.
не понял этот дифф. Ты же эти поля из стейта тут не достаешь и никак не используешь
); | ||
} | ||
|
||
return elem; |
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.
давай через тернарник напишем, красивее же будет
} | ||
} | ||
|
||
export default connect(({view: {lazyLoad, lazyLoadOffset}}) => ({lazyLoad, lazyLoadOffset}))(Screenshot); |
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.
у тебя lazyLoadOffset
должен браться из config
, а не из view
lib/static/modules/action-names.js
Outdated
@@ -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' |
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.
я бы тут images
тоже добавил бы
@@ -22,6 +22,7 @@ function getInitialState(compiledData) { | |||
view: { | |||
viewMode: config.defaultView, | |||
scaleImages: config.scaleImages, | |||
lazyLoadOffset: config.lazyLoadOffset, |
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.
а для чего так делать? В компоненте screenshot
бери это значение просто из config
. К view
же это не относится. К нему относится только lazyLoad
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.
После того, как реализовал через одну опцию, это стало необходимо выгружать во view
, т.к. это уже не просто константа.
const formattedSuites = formatSuitesData(suites); | ||
|
||
return merge({}, state, {gui, autoRun, skips, view: {scaleImages}}, formattedSuites); | ||
return merge({}, state, {gui, autoRun, skips, view: {scaleImages, lazyLoadOffset}}, formattedSuites); |
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.
а lazyLoad
куда потерял? Ты же его тоже должен прокинуть.
Плюс очень путает, что ты взял значение из конфига и прокинул его во view
. Хотя тебе это делать вообще не нужно
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.
уже не актуально
идея с одним параметром норм |
9a76434
to
c965803
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.
в остальном ок
test/lib/config.js
Outdated
@@ -136,4 +136,30 @@ describe('config', () => { | |||
assert.isTrue(parseConfig({}).scaleImages); | |||
}); | |||
}); | |||
|
|||
describe('"lazyLoadOffset" option', () => { | |||
it('should has default balue', () => { |
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.
test/lib/config.js
Outdated
|
||
describe('"lazyLoadOffset" option', () => { | ||
it('should has default balue', () => { | ||
assert.equal(parseConfig({}).lazyLoadOffset, 800); |
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.
вместо 800 укажи значение из дефолтов
@@ -136,4 +136,30 @@ describe('config', () => { | |||
assert.isTrue(parseConfig({}).scaleImages); | |||
}); | |||
}); | |||
|
|||
describe('"lazyLoadOffset" option', () => { |
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.
добавь тест на то, что можно предавать только числа
assert.lengthOf(lazyLoadContainer, 0); | ||
}); | ||
|
||
it('should not load images lazy of lazy load offset is not specified', () => { |
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.
этот тест у тебя сейчас ничем не отличается от предыдущего
c965803
to
dbd0a0d
Compare
No description provided.