Skip to content
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.

Commit

Permalink
Attempt to memoize with Fathom's 'note'
Browse files Browse the repository at this point in the history
Causes an infinite recursion loop!
  • Loading branch information
biancadanforth committed Jul 24, 2019
1 parent 3f59006 commit fd059d4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/extraction/fathom/ruleset_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import {dom, out, rule, ruleset, score, type} from 'fathom-web';
import {dom, out, rule, ruleset, score, type, note} from 'fathom-web';
import {euclidean} from 'fathom-web/clusters';

const TOP_BUFFER = 150;
Expand Down Expand Up @@ -87,6 +87,7 @@ export default class RulesetFactory {

/** Scores fnode by its vertical location relative to the fold */
isAboveTheFold(fnode) {
console.log(fnode.noteFor('image'));
const viewportHeight = 950;
const imageTop = fnode.element.getBoundingClientRect().top;

Expand Down Expand Up @@ -199,6 +200,7 @@ export default class RulesetFactory {
}

isVisible(fnode) {
console.log(fnode.noteFor('image'));
const element = fnode.element;
const rect = element.getBoundingClientRect();
if (rect.width === 0 || rect.height === 0) {
Expand Down Expand Up @@ -258,7 +260,7 @@ export default class RulesetFactory {
* Image rules
*/
// consider all visible img elements
rule(dom('img').when(this.isVisible.bind(this)), type('image')),
rule(dom('img').when(this.isVisible.bind(this)), note(() => ({isVisible: true})).type('image')),
// and divs, which sometimes have CSS background-images
// TODO: Consider a bonus for <img> tags.
rule(dom('div').when(fnode => this.isVisible(fnode) && this.hasBackgroundImage(fnode)), type('image')),
Expand Down

0 comments on commit fd059d4

Please sign in to comment.