-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from asieduernest12/master
Feat bolden newly added text nodes on dynamic sites automatically
- Loading branch information
Showing
3 changed files
with
116 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export default class NodeObserver { | ||
#DEFAULT_MUTATION_OPTIONS = { childList: true, subtree: true }; | ||
|
||
/** @type MutationObserver */ | ||
#observer; | ||
|
||
/** @type MutationCallback */ | ||
#callback; | ||
|
||
/** @type OberverOptions */ | ||
#options; | ||
|
||
/** @type Node */ | ||
#target; | ||
|
||
constructor(target, options, /** @type MutationCallback */ callback) { | ||
this.#observer = new MutationObserver(callback); | ||
this.#options = options ?? this.#DEFAULT_MUTATION_OPTIONS; | ||
this.#target = target; | ||
} | ||
|
||
observe() { | ||
this.#observer.observe(this.#target, this.#options); | ||
} | ||
|
||
destroy() { | ||
this.#observer.disconnect(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* | ||
* provide development utility functions for reporting errors, logging data and logging time | ||
*/ | ||
|
||
/* eslint-disable no-console */ | ||
export default class Logger { | ||
static #isProductionEnv = () => process.env.NODE_ENV === 'production'; | ||
|
||
static logError = (error) => { | ||
if (this.#isProductionEnv()) return; | ||
console.error(error); | ||
}; | ||
|
||
/** | ||
* | ||
* @param {...any} data | ||
* @returns {void} | ||
*/ | ||
static logInfo = (...data) => { | ||
if (this.#isProductionEnv()) return; | ||
|
||
console.log(...data); | ||
}; | ||
|
||
/** | ||
* | ||
* @param {String} label | ||
* @returns {Function} end and display time when called in non production environment | ||
*/ | ||
static logTime = (label) => { | ||
if (this.#isProductionEnv()) { | ||
return () => { | ||
// no-op} | ||
}; | ||
} | ||
console.time(label); | ||
return () => console.timeEnd(label); | ||
}; | ||
} |