Skip to content
This repository was archived by the owner on Jul 30, 2018. It is now read-only.

Intersection Observer Meta #696

Merged
merged 7 commits into from
Sep 22, 2017
Merged

Conversation

agubler
Copy link
Member

@agubler agubler commented Sep 22, 2017

Type: feature

The following has been addressed in the PR:

  • There is a related issue
  • All code matches the style guide
  • Unit or Functional tests are included in the PR

Description:

Builds on #664, updating to use the latest changes in meta (added by by #666).

It is highly likely the functionality will need to be enhanced to cater for the more advanced use-cases in the future.

Includes the intersection observer polyfil

Resolves #644

@agubler agubler requested a review from pottedmeat September 22, 2017 14:26

private _createDetails(options: IntersectionGetOptions, rootNode?: HTMLElement): IntersectionDetail {
const entries = new WeakMap<HTMLElement, ExtendedIntersectionObserverEntry>();
const observer = new global.IntersectionObserver(this._onIntersect(entries), options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The root string from the options object (instead of the root node) is passed when creating an IntersectionObserver. I have a test for this in: 'intersections accept root'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes a lot of sense, thanks (i'll add a test).

I actually tried the root node functionality yesterday but couldn't get it to work (just thought I had done it wrong.)

const observer = new global.IntersectionObserver(this._onIntersect(entries), options);
const details = { observer, entries, ...options };

this._details.set(JSON.stringify(options), details);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I was wondering about this when I was working on it. If the key order changes, will this encode the same thing? Is it a big deal if it doesn't? I had gone with the approach of using JSON.stringify([root, rootMargin, thresholds]) to make sure the structure stays the same.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what your saying, feels like a pretty edge case though.

@agubler agubler force-pushed the feature-meta-intersection branch from 2d1a479 to c68e86b Compare September 22, 2017 15:05
@agubler agubler requested a review from kitsonk September 22, 2017 15:29
Copy link
Member

@kitsonk kitsonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple comments/thoughts

return details.entries.get(node) || defaultIntersection;
}

public has(key: string | number, options?: IntersectionGetOptions): boolean {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some JSDOC would be nice

}

private _getDetails(options: IntersectionGetOptions = {}): IntersectionDetail | undefined {
return this._details.get(JSON.stringify(options));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit concerned about GC with this... I can understand why stringifying is useful to create a key here, but it is a map, which means it will have strong references to the values, which means that they won't ever get released. Shouldn't here be a destruction handle in the constructor to .clear() the Map?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use Maps across the widget-core, should we raise an separate issue to discuss this?

export class Intersection extends Base {
private readonly _details: Map<string, IntersectionDetail> = new Map();

public get(key: string, options: IntersectionGetOptions = {}): IntersectionResult {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some JSDOC would be nice

});

export class Intersection extends Base {
private readonly _details: Map<string, IntersectionDetail> = new Map();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit, but you could private readonly _details = new Map<string, IntersectionDetail>();

@agubler agubler merged commit fb9f7d0 into dojo:master Sep 22, 2017
@dylans dylans added this to the 2017.09 milestone Sep 25, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants