From fd059d49690d3b2fe617e55763c76ddec7c40f16 Mon Sep 17 00:00:00 2001 From: Bianca Danforth Date: Wed, 24 Jul 2019 14:27:24 -0700 Subject: [PATCH] Attempt to memoize with Fathom's 'note' Causes an infinite recursion loop! --- src/extraction/fathom/ruleset_factory.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/extraction/fathom/ruleset_factory.js b/src/extraction/fathom/ruleset_factory.js index 65fa7d4..1624126 100644 --- a/src/extraction/fathom/ruleset_factory.js +++ b/src/extraction/fathom/ruleset_factory.js @@ -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; @@ -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; @@ -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) { @@ -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 tags. rule(dom('div').when(fnode => this.isVisible(fnode) && this.hasBackgroundImage(fnode)), type('image')),