Skip to content

Commit

Permalink
Rename amend to extend
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Oct 14, 2024
1 parent dca43e9 commit 73d2252
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
12 changes: 6 additions & 6 deletions plugins/embed-optimizer/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Embed Optimizer module for Optimization Detective
*
* When a URL metric is being collected by Optimization Detective, this module adds a ResizeObserver to keep track of
* the changed heights for embed blocks. This data is amended onto the element data of the pending URL metric when it
* is submitted for storage.
* the changed heights for embed blocks. This data is extended/amended onto the element data of the pending URL metric
* when it is submitted for storage.
*/

const consoleLogPrefix = '[Embed Optimizer]';
Expand All @@ -16,7 +16,7 @@ const consoleLogPrefix = '[Embed Optimizer]';
* @typedef {import("../optimization-detective/types.d.ts").InitializeArgs} InitializeArgs
* @typedef {import("../optimization-detective/types.d.ts").FinalizeArgs} FinalizeArgs
* @typedef {import("../optimization-detective/types.d.ts").FinalizeCallback} FinalizeCallback
* @typedef {import("../optimization-detective/types.d.ts").AmendedElementData} AmendedElementData
* @typedef {import("../optimization-detective/types.d.ts").ExtendedElementData} ExtendedElementData
*/

/**
Expand Down Expand Up @@ -76,11 +76,11 @@ export function initialize( { isDebug } ) {
export async function finalize( {
isDebug,
getElementData,
amendElementData,
extendElementData,
} ) {
for ( const [ xpath, domRect ] of loadedElementContentRects.entries() ) {
try {
amendElementData( xpath, {
extendElementData( xpath, {
resizedBoundingClientRect: domRect,
} );
if ( isDebug ) {
Expand All @@ -94,7 +94,7 @@ export async function finalize( {
}
} catch ( err ) {
error(
`Failed to amend ${ xpath } with resizedBoundingClientRect data:`,
`Failed to extend element data for ${ xpath } with resizedBoundingClientRect:`,
domRect,
err
);
Expand Down
28 changes: 13 additions & 15 deletions plugins/optimization-detective/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* @typedef {import("./types.d.ts").URLMetric} URLMetric
* @typedef {import("./types.d.ts").URLMetricGroupStatus} URLMetricGroupStatus
* @typedef {import("./types.d.ts").Extension} Extension
* @typedef {import("./types.d.ts").AmendedRootData} AmendedRootData
* @typedef {import("./types.d.ts").AmendedElementData} AmendedElementData
* @typedef {import("./types.d.ts").ExtendedRootData} ExtendedRootData
* @typedef {import("./types.d.ts").ExtendedElementData} ExtendedElementData
*/

const win = window;
Expand Down Expand Up @@ -138,7 +138,7 @@ let urlMetric;
* Reserved root property keys.
*
* @see {URLMetric}
* @see {AmendedElementData}
* @see {ExtendedElementData}
* @type {Set<string>}
*/
const reservedRootPropertyKeys = new Set( [ 'url', 'viewport', 'elements' ] );
Expand All @@ -155,13 +155,11 @@ function getRootData() {
}

/**
* Amends root URL metric data.
* Extends root URL metric data.
*
* @todo Would "extend" be better than "amend"? Or something else?
*
* @param {AmendedRootData} properties
* @param {ExtendedRootData} properties
*/
function amendRootData( properties ) {
function extendRootData( properties ) {
for ( const key of Object.getOwnPropertyNames( properties ) ) {
if ( reservedRootPropertyKeys.has( key ) ) {
throw new Error( `Disallowed setting of key '${ key }' on root.` );
Expand All @@ -181,7 +179,7 @@ const elementsByXPath = new Map();
* Reserved element property keys.
*
* @see {ElementData}
* @see {AmendedRootData}
* @see {ExtendedRootData}
* @type {Set<string>}
*/
const reservedElementPropertyKeys = new Set( [
Expand Down Expand Up @@ -210,12 +208,12 @@ function getElementData( xpath ) {
}

/**
* Amends element data.
* Extends element data.
*
* @param {string} xpath XPath.
* @param {AmendedElementData} properties Properties.
* @param {string} xpath XPath.
* @param {ExtendedElementData} properties Properties.
*/
function amendElementData( xpath, properties ) {
function extendElementData( xpath, properties ) {
if ( ! elementsByXPath.has( xpath ) ) {
throw new Error( `Unknown element with XPath: ${ xpath }` );
}
Expand Down Expand Up @@ -529,8 +527,8 @@ export default async function detect( {
isDebug,
getRootData,
getElementData,
amendElementData,
amendRootData,
extendElementData,
extendRootData,
} );
} catch ( err ) {
error(
Expand Down
8 changes: 4 additions & 4 deletions plugins/optimization-detective/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface ElementData {
boundingClientRect: DOMRectReadOnly;
}

export type AmendedElementData = ExcludeProps<ElementData>
export type ExtendedElementData = ExcludeProps<ElementData>

export interface URLMetric {
url: string;
Expand All @@ -22,7 +22,7 @@ export interface URLMetric {
elements: ElementData[];
}

export type AmendedRootData = ExcludeProps<URLMetric>
export type ExtendedRootData = ExcludeProps<URLMetric>

export interface URLMetricGroupStatus {
minimumViewportWidth: number;
Expand All @@ -37,9 +37,9 @@ export type InitializeCallback = ( args: InitializeArgs ) => void;

export type FinalizeArgs = {
readonly getRootData: () => URLMetric,
readonly amendRootData: ( properties: AmendedRootData ) => void,
readonly extendRootData: ( properties: ExtendedRootData ) => void,
readonly getElementData: ( xpath: string ) => ElementData|null,
readonly amendElementData: ( xpath: string, properties: AmendedElementData ) => void,
readonly extendElementData: (xpath: string, properties: ExtendedElementData ) => void,
readonly isDebug: boolean,
};

Expand Down

0 comments on commit 73d2252

Please sign in to comment.