Skip to content

Commit

Permalink
Merge 6988457 into a7c159f
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Jan 10, 2018
2 parents a7c159f + 6988457 commit b39db47
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 23 deletions.
14 changes: 9 additions & 5 deletions dist/infinitegrid.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/infinitegrid.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/infinitegrid.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/infinitegrid.min.js.map

Large diffs are not rendered by default.

14 changes: 9 additions & 5 deletions dist/infinitegrid.pkgd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/infinitegrid.pkgd.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/infinitegrid.pkgd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/infinitegrid.pkgd.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/parallax.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/parallax.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/InfiniteGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,15 +777,16 @@ ig.on("imageError", e => {
});
}
_postLayout(fromCache, items, isAppend, isTrusted) {
const {startCursor, endCursor} = this._status;
const outline = this._items.getOutline(
isAppend ? this._status.endCursor : this._status.startCursor,
isAppend ? endCursor : startCursor,
isAppend ? "end" : "start");

let fromRelayout = false;

if (fromCache) {
const cacheOutline = this._items.getOutline(
isAppend ? this._status.endCursor + 1 : this._status.startCursor - 1,
isAppend ? endCursor + 1 : startCursor - 1,
isAppend ? "start" : "end");

fromRelayout = outline.length === cacheOutline.length ?
Expand Down Expand Up @@ -818,7 +819,9 @@ ig.on("imageError", e => {
complete: () => {
layouted = this._layout[method](
this._renderer.updateSize(items),
outline
this._items.getOutline(
isAppend ? endCursor : startCursor,
isAppend ? "end" : "start")
);
this._postImageLoaded(fromCache, layouted, isAppend, isTrusted);
},
Expand Down
48 changes: 48 additions & 0 deletions test/unit/InfiniteGrid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {getItems, insert, checkLayoutComplete} from "./helper/TestHelper";
import {APPEND, PREPEND, LOADING_APPEND, LOADING_PREPEND} from "../../src/consts";
import {innerWidth, innerHeight} from "../../src/utils";
import {DEFENSE_BROWSER} from "../../src/consts";
import {expectConnectGroupsOutline} from "./helper/common";

/* eslint-disable */
describe("InfiniteGrid Test", function() {
Expand Down Expand Up @@ -402,6 +403,53 @@ describe("InfiniteGrid Test", function() {
this.inst.append(`<div>HEADER<img src="/base/test/unit/image/3.jpg" />FOOTER</div><div>HEADER<img src="/1.jpg">FOOTER</div>`);
});
});
describe(`When image processing, fit test`, function() {
beforeEach(() => {
this.el = sandbox();
this.el.innerHTML = "<div id='infinite'></div>";
this.inst = new InfiniteGrid("#infinite", {
margin: 5,
isOverflowScroll: true,
});
this.inst.setLayout(GridLayout);
});
afterEach(() => {
if (this.inst) {
this.inst.destroy();
this.inst = null;
}
cleanup();
});
it.only(`should check outline when image processing and fit occur at the same time`, done => {
const item1 = `<div style="height:100px">HEADER<img src="/base/test/unit/image/3.jpg" />FOOTER</div><div>HEADER<img src="/1.jpg">FOOTER</div>`;
const layoutComplete2 = sinon.spy(e => {
const length = this.inst._items._data.length;

const group1 = this.inst._items._data[length - 2];
const group2 = this.inst._items._data[length - 1];
expectConnectGroupsOutline(group1, group2);
done();
});
insert(this.inst, true, () => {
expect(this.inst._isImageProcessing()).to.be.false;
const container = this.el.querySelector("#infinite");

container.scrollTop = 50000;

const pos = this.inst._watcher.getScrollPos();

setTimeout(() => {
this.inst._recycle(true);
this.inst.on("layoutComplete", layoutComplete2);
this.inst.append(item1);
expect(this.inst._isImageProcessing()).to.be.true;
this.inst._fit("before");
}, 10);

}, 10, 20);

});
});
[true, false].forEach(isOverflowScroll => {
describe(`When appending/prepending loadingStart/loaingEnd event Test (isOverflowScroll: ${isOverflowScroll})`, function() {
beforeEach(() => {
Expand Down

0 comments on commit b39db47

Please sign in to comment.