Skip to content

Commit

Permalink
refactor: remove the targetElement property from the config
Browse files Browse the repository at this point in the history
  • Loading branch information
IamSebastianDev committed Apr 29, 2023
1 parent 9a22e1b commit 068cc8c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
9 changes: 7 additions & 2 deletions src/lib/Vay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,15 @@ export class Vay<T extends Dictionary<Record<string, Phrase>>> {
}
}

render(): void {
render(targetElement: HTMLElement): void {
if (!targetElement) {
this._report(VayError.MISSING_RENDER_TARGET);
return;
}

// Get all elements with a attribute matching the supplied targetAttribute
// Iterate them to set the static translations
const markedElements = [...this._targetElement.querySelectorAll(`[${this._targetAttribute}]`)];
const markedElements = [...targetElement.querySelectorAll(`[${this._targetAttribute}]`)];
markedElements.map((element) => {
this._processToken(element);
this._processAttributes(element);
Expand Down
1 change: 1 addition & 0 deletions src/lib/VayError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export enum VayError {
NO_DICT = 'No dictionary found.',
NO_PHRASE = 'No phrase could be matched to token [{{phrase}}].',
MALFORMED_PHRASE = 'The token [{{token}}] is not a valid Phrase containing only numeric keys to evaluate for plural forms.',
MISSING_RENDER_TARGET = 'The target supplied to the `render` function is not a valid Element.',
}
1 change: 0 additions & 1 deletion src/lib/defineConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { VayConfig } from '../types';

const defaultConfig: VayConfig = {
targetAttribute: 'vay',
targetElement: document.documentElement,
ignoreAttributes: false,
removeAttributesOnRender: false,
quiet: true,
Expand Down
9 changes: 1 addition & 8 deletions src/types/VayConfig.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ export type VayConfig = {
* The default tag used is 'vay'.
*/
targetAttribute: string;
/**
* @type { Element }
* @description
* The targetElement is the element that acts as root for the static translation. All children
* of the element will be checked for translation tags. By default, `document.documentElement` is
* used as root.
*/
targetElement: Element;

/**
* @type { boolean }
* @description
Expand Down

0 comments on commit 068cc8c

Please sign in to comment.