Skip to content

Commit

Permalink
Rename Cacheable -> Capturable
Browse files Browse the repository at this point in the history
  • Loading branch information
eoghanmurray committed Mar 25, 2024
1 parent a3ce3e0 commit 7434552
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/rrdom/src/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ function diffProps(
} else if (newTree.tagName === 'IFRAME' && name === 'srcdoc') continue;
else oldTree.setAttribute(name, newValue);

if (assetManager?.isCacheable(oldTree, name, newValue)) {
if (assetManager?.isCapturable(oldTree, name, newValue)) {
// can possibly remove the attribute again if it hasn't loaded yet
assetManager.manageAttribute(oldTree, rrnodeMirror.getId(newTree), name);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/rrdom/test/diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ describe('diff algorithm for rrdom', () => {
beforeEach(() => {
assetManager = fromPartial({
manageAttribute: jest.fn(),
isCacheable: jest.fn(),
isCapturable: jest.fn(),
});
replayer.assetManager = assetManager;
});
Expand All @@ -484,7 +484,7 @@ describe('diff algorithm for rrdom', () => {
const sn2 = Object.assign({}, elementSn, { tagName });
rrDocument.mirror.add(rrNode, sn2);

(assetManager.isCacheable as jest.Mock)
(assetManager.isCapturable as jest.Mock)
.mockReturnValueOnce(true)
.mockReturnValue(false);
rrNode.attributes = { src: 'image.png', class: 'node' };
Expand Down
4 changes: 2 additions & 2 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
getInputType,
toLowerCase,
getUrlsFromSrcset,
isAttributeCacheable,
isAttributeCapturable,
} from './utils';

let _id = 1;
Expand Down Expand Up @@ -680,7 +680,7 @@ function serializeElementNode(
));

// save assets offline
if (value && onAssetDetected && isAttributeCacheable(n, attr.name)) {
if (value && onAssetDetected && isAttributeCapturable(n, attr.name)) {
if (attr.name === 'srcset') {
assets.push(...getUrlsFromSrcset(value));
} else {
Expand Down
6 changes: 3 additions & 3 deletions packages/rrweb-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export function getUrlsFromSrcset(srcset: string): string[] {
return urls;
}

export const CACHEABLE_ELEMENT_ATTRIBUTE_COMBINATIONS = new Map([
export const CAPTURABLE_ELEMENT_ATTRIBUTE_COMBINATIONS = new Map([
['IMG', new Set(['src', 'srcset'])],
['VIDEO', new Set(['src'])],
['AUDIO', new Set(['src'])],
Expand All @@ -378,8 +378,8 @@ export const CACHEABLE_ELEMENT_ATTRIBUTE_COMBINATIONS = new Map([
['cursor', new Set(['href'])],
]);

export function isAttributeCacheable(n: Element, attribute: string): boolean {
const acceptedAttributesSet = CACHEABLE_ELEMENT_ATTRIBUTE_COMBINATIONS.get(
export function isAttributeCapturable(n: Element, attribute: string): boolean {
const acceptedAttributesSet = CAPTURABLE_ELEMENT_ATTRIBUTE_COMBINATIONS.get(
n.nodeName,
);
if (!acceptedAttributesSet) {
Expand Down
8 changes: 4 additions & 4 deletions packages/rrweb-snapshot/test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @jest-environment jsdom
*/
import { isAttributeCacheable, isNodeMetaEqual } from '../src/utils';
import { isAttributeCapturable, isNodeMetaEqual } from '../src/utils';
import { NodeType, serializedNode, serializedNodeWithId } from '@rrweb/types';

describe('utils', () => {
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('utils', () => {
});
});

describe('isAttributeCacheable()', () => {
describe('isAttributeCapturable()', () => {
const validAttributeCombinations = [
['img', ['src', 'srcset']],
['video', ['src']],
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('utils', () => {
const element = document.createElement(tagName);
attributes.forEach((attribute) => {
it(`should correctly identify <${tagName} ${attribute}> as cacheable`, () => {
expect(isAttributeCacheable(element, attribute)).toBe(true);
expect(isAttributeCapturable(element, attribute)).toBe(true);
});
});
});
Expand All @@ -187,7 +187,7 @@ describe('utils', () => {
const element = document.createElement(tagName);
attributes.forEach((attribute) => {
it(`should correctly identify <${tagName} ${attribute}> as NOT cacheable`, () => {
expect(isAttributeCacheable(element, attribute)).toBe(false);
expect(isAttributeCapturable(element, attribute)).toBe(false);
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ export default class MutationBuffer {
));
if (
transformedValue &&
this.assetManager.isAttributeCacheable(target, attributeName)
this.assetManager.isAttributeCapturable(target, attributeName)
) {
if (attributeName === 'srcset') {
getSourcesFromSrcset(transformedValue).forEach((url) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/rrweb/src/record/observers/asset-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { encode } from 'base64-arraybuffer';
import { patch } from '../../utils';

import type { recordOptions } from '../../types';
import { isAttributeCacheable } from 'rrweb-snapshot';
import { isAttributeCapturable } from 'rrweb-snapshot';

export default class AssetManager {
private urlObjectMap = new Map<string, File | Blob | MediaSource>();
Expand Down Expand Up @@ -190,7 +190,7 @@ export default class AssetManager {
return { status: 'capturing' };
}

public isAttributeCacheable(n: Element, attribute: string): boolean {
return isAttributeCacheable(n, attribute);
public isAttributeCapturable(n: Element, attribute: string): boolean {
return isAttributeCapturable(n, attribute);
}
}
8 changes: 4 additions & 4 deletions packages/rrweb/src/replay/asset-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
captureAssetsParam,
} from '@rrweb/types';
import { deserializeArg } from '../canvas/deserialize-args';
import { getSourcesFromSrcset, isAttributeCacheable } from 'rrweb-snapshot';
import { getSourcesFromSrcset, isAttributeCapturable } from 'rrweb-snapshot';
import type { RRElement } from 'rrdom';
import { updateSrcset } from './update-srcset';

Expand Down Expand Up @@ -120,12 +120,12 @@ export default class AssetManager implements RebuildAssetManagerInterface {
};
}

public isCacheable(
public isCapturable(
n: RRElement | Element,
attribute: string,
value: string,
): boolean {
if (!isAttributeCacheable(n as Element, attribute)) return false;
if (!isAttributeCapturable(n as Element, attribute)) return false;

if (attribute === 'srcset') {
return getSourcesFromSrcset(value).some((source) =>
Expand Down Expand Up @@ -163,7 +163,7 @@ export default class AssetManager implements RebuildAssetManagerInterface {
attribute: string,
): Promise<unknown> {
const originalValue = node.getAttribute(attribute);
if (!originalValue || !this.isCacheable(node, attribute, originalValue))
if (!originalValue || !this.isCapturable(node, attribute, originalValue))
return false;

const promises: Promise<unknown>[] = [];
Expand Down
4 changes: 2 additions & 2 deletions packages/rrweb/test/replay/asset-unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ describe('AssetManager', () => {
},
);
it(`should correctly identify <${element} ${attribute}=${value} /> as cacheable for origins ${origins}`, () => {
expect(assetManager.isCacheable(element, attribute, value)).toBe(true);
expect(assetManager.isCapturable(element, attribute, value)).toBe(true);
});
});

Expand All @@ -282,7 +282,7 @@ describe('AssetManager', () => {
},
);
it(`should correctly identify <${element} ${attribute}=${value} /> as NOT cacheable for origins ${origins}`, () => {
expect(assetManager.isCacheable(element, attribute, value)).toBe(false);
expect(assetManager.isCapturable(element, attribute, value)).toBe(false);
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ export declare abstract class RebuildAssetManagerInterface {
abstract get(url: string): RebuildAssetManagerStatus;
abstract whenReady(url: string): Promise<RebuildAssetManagerFinalStatus>;
abstract reset(config?: captureAssetsParam | undefined): void;
abstract isCacheable(n: Element, attribute: string, value: string): boolean;
abstract isCapturable(n: Element, attribute: string, value: string): boolean;
abstract isURLOfCacheableOrigin(url: string): boolean;
abstract manageAttribute(n: Element, id: number, attribute: string): void;
}
Expand Down

0 comments on commit 7434552

Please sign in to comment.