Skip to content

Commit

Permalink
feat: Remove plugins related code, which is not used
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea committed Oct 27, 2023
1 parent 6987090 commit 2bfd19f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 366 deletions.
35 changes: 3 additions & 32 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ function record<T = eventWithTime>(
userTriggeredOnInput = false,
collectFonts = false,
inlineImages = false,
plugins,
keepIframeSrcFn = () => false,
ignoreCSSAttributes = new Set([]),
errorHandler,
Expand Down Expand Up @@ -197,11 +196,7 @@ function record<T = eventWithTime>(
let incrementalSnapshotCount = 0;

const eventProcessor = (e: eventWithTime): T => {
for (const plugin of plugins || []) {
if (plugin.eventProcessor) {
e = plugin.eventProcessor(e);
}
}
// We ignore plugins here, as we do not have any
if (
packFn &&
// Disable packing events which will be emitted to parent frames.
Expand Down Expand Up @@ -322,16 +317,8 @@ function record<T = eventWithTime>(

/**
* Exposes mirror to the plugins
* We ignore plugins here, as we don't use any
*/
for (const plugin of plugins || []) {
if (plugin.getMirror)
plugin.getMirror({
nodeMirror: mirror,
crossOriginIframeMirror: iframeManager.crossOriginIframeMirror,
crossOriginIframeStyleMirror:
iframeManager.crossOriginIframeStyleMirror,
});
}

const processedNodeManager = new ProcessedNodeManager();

Expand Down Expand Up @@ -612,23 +599,7 @@ function record<T = eventWithTime>(
processedNodeManager,
canvasManager,
ignoreCSSAttributes,
plugins:
plugins
?.filter((p) => p.observer)
?.map((p) => ({
observer: p.observer!,
options: p.options,
callback: (payload: object) =>
wrappedEmit(
wrapEvent({
type: EventType.Plugin,
data: {
plugin: p.name,
payload,
},
}),
),
})) || [],
plugins: [],
},
hooks,
);
Expand Down
8 changes: 1 addition & 7 deletions packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1440,12 +1440,7 @@ export function initObservers(
const customElementObserver = initCustomElementObserver(o);

// plugins
const pluginHandlers: listenerHandler[] = [];
for (const plugin of o.plugins) {
pluginHandlers.push(
plugin.observer(plugin.callback, currentWindow, plugin.options),
);
}
// we ignore plugins here, as we don't have any

return callbackWrapper(() => {
mutationBuffers.forEach((b) => b.reset());
Expand All @@ -1462,7 +1457,6 @@ export function initObservers(
fontObserver();
selectionObserver();
customElementObserver();
pluginHandlers.forEach((h) => h());
});
}

Expand Down
47 changes: 8 additions & 39 deletions packages/rrweb/src/replay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,8 @@ export class Replayer {

/**
* Exposes mirror to the plugins
* We ignore plugins here, as we don't have any
*/
for (const plugin of this.config.plugins || []) {
if (plugin.getMirror) plugin.getMirror({ nodeMirror: this.mirror });
}

this.emitter.on(ReplayerEvents.Flush, () => {
if (this.usingVirtualDom) {
Expand Down Expand Up @@ -236,11 +234,7 @@ export class Replayer {
else if (data.source === IncrementalSource.StyleDeclaration)
this.applyStyleDeclaration(data, styleSheet);
},
afterAppend: (node: Node, id: number) => {
for (const plugin of this.config.plugins || []) {
if (plugin.onBuild) plugin.onBuild(node, { id, replayer: this });
}
},
// we ignore plugins here, as we don't have any
};
if (this.iframe.contentDocument)
try {
Expand Down Expand Up @@ -723,9 +717,7 @@ export class Replayer {
castFn();
}

for (const plugin of this.config.plugins || []) {
if (plugin.handler) plugin.handler(event, isSync, { replayer: this });
}
// we ignore plugins here, as we don't have any

this.service.send({ type: 'CAST_EVENT', payload: { event } });

Expand Down Expand Up @@ -778,13 +770,7 @@ export class Replayer {
const collected: AppendedIframe[] = [];
const afterAppend = (builtNode: Node, id: number) => {

Check warning on line 771 in packages/rrweb/src/replay/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb/src/replay/index.ts#L771

[@typescript-eslint/no-unused-vars] 'id' is defined but never used.
this.collectIframeAndAttachDocument(collected, builtNode);
for (const plugin of this.config.plugins || []) {
if (plugin.onBuild)
plugin.onBuild(builtNode, {
id,
replayer: this,
});
}
// we ignore plugins here, as we don't have any
};

/**
Expand Down Expand Up @@ -877,7 +863,7 @@ export class Replayer {
type TMirror = typeof mirror extends Mirror ? Mirror : RRDOMMirror;

const collected: AppendedIframe[] = [];
const afterAppend = (builtNode: Node, id: number) => {
const afterAppend = (builtNode: Node, _id: number) => {

Check warning on line 866 in packages/rrweb/src/replay/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb/src/replay/index.ts#L866

[@typescript-eslint/no-unused-vars] '_id' is defined but never used.
this.collectIframeAndAttachDocument(collected, builtNode);
const sn = (mirror as TMirror).getMeta(builtNode as unknown as TNode);
if (
Expand All @@ -892,14 +878,7 @@ export class Replayer {
}

// Skip the plugin onBuild callback in the virtual dom mode
if (this.usingVirtualDom) return;
for (const plugin of this.config.plugins || []) {
if (plugin.onBuild)
plugin.onBuild(builtNode, {
id,
replayer: this,
});
}
// we ignore plugins here, as we don't have any
};

buildNodeWithSN(mutation.node, {
Expand Down Expand Up @@ -1519,13 +1498,7 @@ export class Replayer {
);
return;
}
const afterAppend = (node: Node | RRNode, id: number) => {
// Skip the plugin onBuild callback for virtual dom
if (this.usingVirtualDom) return;
for (const plugin of this.config.plugins || []) {
if (plugin.onBuild) plugin.onBuild(node, { id, replayer: this });
}
};
// we ignore plugins here, as we don't have any

const target = buildNodeWithSN(mutation.node, {
doc: targetDoc as Document, // can be Document or RRDocument
Expand All @@ -1537,7 +1510,6 @@ export class Replayer {
* caveat: `afterAppend` only gets called on child nodes of target
* we have to call it again below when this target was added to the DOM
*/
afterAppend,
}) as Node | RRNode;

// legacy data, we should not have -1 siblings any more
Expand Down Expand Up @@ -1612,10 +1584,7 @@ export class Replayer {
} else {
(parent as TNode).appendChild(target as TNode);
}
/**
* target was added, execute plugin hooks
*/
afterAppend(target, mutation.node.id);
// we ignore plugins here, as we don't have any

/**
* https://github.com/rrweb-io/rrweb/pull/887
Expand Down
Loading

0 comments on commit 2bfd19f

Please sign in to comment.