Skip to content

Commit

Permalink
Enhance Page to take a PageDetails upon construction.
Browse files Browse the repository at this point in the history
With #private variables, we need to move away from having code in the base
class that can use overrides in the subclasses.  Instead, we will need to pass
them in through the constructor or other mechanisms.  Here, we are adding some
items similar to what we already use, but can do differently.

Issue #130.

␄
  • Loading branch information
Mike Castle committed Oct 8, 2023
1 parent 0dfd511 commit 70fe510
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions linkedin-tool.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -1751,6 +1751,8 @@
*/
_pathname;

#pageReadyCSS

/**
* @type {string} - CSS selector for capturing clicks on this page. If
* overridden, then the class should also provide a _onClick() method.
Expand Down Expand Up @@ -1788,12 +1790,34 @@
condition: '!inputFocus && !inDialog',
};

/** Create a Page instance. */
constructor() {
/**
* @typedef {object} PageDetails
* @property {string|RegExp} [pathname=RegExp] - Pathname portion of the
* URL this page should handle.
* @property {string} [pageReadyCSS='body'] - CSS selector that is used to
* detect that the page is loaded enough to activate.
*/

/**
* Create a Page instance.
* @param {PageDetails} details - Details about the instance.
*/
constructor(details = {}) {
if (new.target === Page) {
throw new TypeError('Abstract class; do not instantiate directly.');
}
if (details.pathname) {
if (details.pathname instanceof RegExp) {
this.#pathnameRE = details.pathname;
} else {
this.#pathnameRE = RegExp(`^${details.pathname}$`, 'u');
}
}
({
pageReadyCSS: this.#pageReadyCSS = 'body',
} = details);
this.#logger = new Logger(this.constructor.name);
this.#logger.log('Base page constructed', this);
}

/**
Expand Down

0 comments on commit 70fe510

Please sign in to comment.