Skip to content

Commit

Permalink
Improve doc blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
snewcomer committed Aug 21, 2020
1 parent 6469455 commit aabb579
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
23 changes: 12 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class IntersectionObserverAdmin extends Notifications {
* Adds element to observe via IntersectionObserver and stores element + relevant callbacks and observer options in static
* administrator for lookup in the future
*
* @method add
* @method observe
* @param {HTMLElement | Window} element
* @param {Object} options
* @public
Expand Down Expand Up @@ -135,15 +135,15 @@ export default class IntersectionObserverAdmin extends Notifications {
protected setupObserver(element: HTMLElement, options: IOptions): void {
const { root = window } = options;

// find shared root element (window or target HTMLElement)
// First - find shared root element (window or target HTMLElement)
// this root is responsible for coordinating it's set of elements
const potentialRootMatch:
| PotentialRootEntry
| null
| undefined = this._findRoot(root);
| undefined = this._findRootFromRegistry(root);

// third if there is a matching root, see if an existing entry with the same options
// regardless of sort order. This is a bit of work
// Second - if there is a matching root, see if an existing entry with the same options
// regardless of sort order. This is a bit of work
let matchingEntryForRoot;
if (potentialRootMatch) {
matchingEntryForRoot = this._determineMatchingElements(
Expand Down Expand Up @@ -252,12 +252,12 @@ export default class IntersectionObserverAdmin extends Notifications {

/**
* { root: { stringifiedOptions: { observer, elements: []...] } }
* @method _findRoot
* @method _findRootFromRegistry
* @param {HTMLElement|Window} root
* @private
* @return {Object} of elements that share same root
*/
private _findRoot(
private _findRootFromRegistry(
root: HTMLElement | Window
): PotentialRootEntry | null | undefined {
if (this.elementRegistry) {
Expand All @@ -275,9 +275,10 @@ export default class IntersectionObserverAdmin extends Notifications {
*/
private _findMatchingRootEntry(options: IOptions): EntryForKey | undefined {
const { root = window } = options;
const matchingRoot: PotentialRootEntry | null | undefined = this._findRoot(
root
);
const matchingRoot:
| PotentialRootEntry
| null
| undefined = this._findRootFromRegistry(root);

if (matchingRoot) {
const stringifiedOptions: string = this._stringifyOptions(options);
Expand Down Expand Up @@ -334,7 +335,7 @@ export default class IntersectionObserverAdmin extends Notifications {
if (a && b && typeof a === 'object' && typeof b === 'object') {
// complex comparison for only type of [object Object]
for (const key in a) {
if (a.hasOwnProperty(key)) {
if (Object.prototype.hasOwnProperty.call(a, key)) {
// recursion to check nested
if (this._areOptionsSame(a[key], b[key]) === false) {
return false;
Expand Down
5 changes: 3 additions & 2 deletions src/registry.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// fix by importing IOptions
export interface IOptions {
[key: string]: any;
}
Expand All @@ -23,8 +24,8 @@ export default class Registry {
* @method add
* @param {HTMLElement | Window} element - the item to add to root element registry
* @param {IOption} options
* @param {IOption.root} root - contains optional root e.g. window, container div, etc
* @param {IOption.watcher} observer - optional
* @param {IOption.root} [root] - contains optional root e.g. window, container div, etc
* @param {IOption.watcher} [observer] - optional
* @public
*/
public addElement(element: HTMLElement | Window, options?: IOptions): void {
Expand Down

0 comments on commit aabb579

Please sign in to comment.