Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima Voytenko committed Feb 19, 2021
1 parent 054f8fa commit cc00b43
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build-system/global-configs/experiments-const.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"BENTO_AUTO_UPGRADE": false,
"INI_LOAD_INOB": false,
"V1_IMG_VIDEO": false,
"V1_IMG_DEFERRED_BUILD": false,
"WITHIN_VIEWPORT_INOB": false
}
4 changes: 2 additions & 2 deletions builtins/amp-img.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const ATTRIBUTES_TO_PROPAGATE = [
export class AmpImg extends BaseElement {
/** @override @nocollapse */
static V1() {
return V1_IMG_VIDEO;
return V1_IMG_DEFERRED_BUILD;
}

/** @override @nocollapse */
Expand Down Expand Up @@ -340,7 +340,7 @@ export class AmpImg extends BaseElement {

/** @override */
unlayoutCallback() {
if (!AmpImg.V1()) {
if (AmpImg.V1()) {
return;
}

Expand Down
13 changes: 10 additions & 3 deletions src/service/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ export class Builder {
/** @private */
docVisibilityChanged_() {
const vs = this.ampdoc_.getVisibilityState();
if (vs != VisibilityState.PAUSED && vs != VisibilityState.INACTIVE) {
if (
(vs =
VisibilityState.VISIBLE ||
vs == VisibilityState.HIDDEN ||
vs == VisibilityState.PRERENDER)
) {
this.targets_.forEach((_, target) => this.maybeBuild_(target));
}
}
Expand All @@ -138,8 +143,10 @@ export class Builder {
*/
waitParsing_(target) {
const parsingTargets = this.parsingTargets_;
if (parsingTargets && !parsingTargets.includes(target)) {
parsingTargets.push(target);
if (parsingTargets) {
if (!parsingTargets.includes(target)) {
parsingTargets.push(target);
}
this.checkParsing_();
} else {
this.maybeBuild_(target);
Expand Down
27 changes: 20 additions & 7 deletions testing/intersection-observer-stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export function installIntersectionObserverStub(sandbox, win) {
}

class IntersectionObservers {
/**
* @param {!Object} sandbox
* @param {!Window} win
*/
constructor(sandbox, win) {
const observers = new Set();
this.observers = observers;
Expand All @@ -37,16 +41,19 @@ class IntersectionObservers {
});
}

/**
* @param {!Element} target
* @return {boolean}
*/
isObserved(target) {
let found = false;
this.observers.forEach((observer) => {
if (observer.elements.has(target)) {
found = true;
}
});
return found;
return Array.from(this.observers).some((observer) =>
observer.elements.has(target)
);
}

/**
* @param {!IntersectionObserverEntry|!Array<IntersectionObserverEntry>} entryOrEntries
*/
notifySync(entryOrEntries) {
const entries = Array.isArray(entryOrEntries)
? entryOrEntries
Expand Down Expand Up @@ -74,10 +81,16 @@ class IntersectionObserverStub {
onDisconnect();
}

/**
* @param {!Element} element
*/
observe(element) {
this.elements.add(element);
}

/**
* @param {!Element} element
*/
unobserve(element) {
this.elements.delete(element);
}
Expand Down

0 comments on commit cc00b43

Please sign in to comment.