Skip to content

Commit

Permalink
obsolete processedEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkirtzel committed Dec 18, 2024
1 parent d44314b commit e6a2e23
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 39 deletions.
30 changes: 1 addition & 29 deletions packages/sources/datalayer/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('source dataLayer', () => {

sourceDataLayer({ elb });
expect(isArray(window.dataLayer)).toBe(true);
expect((window.dataLayer as DataLayer)!.length).toBe(0);
expect((window.dataLayer as unknown as DataLayer)!.length).toBe(0);
});

test('init existing', () => {
Expand Down Expand Up @@ -156,34 +156,6 @@ describe('source dataLayer', () => {
expect(originalArr).toEqual([]);
});

test('duplicate prevention', () => {
const processedEvents = new Set<string>();
processedEvents.add('foo');
sourceDataLayer({ elb, processedEvents });

dataLayer.push({ event: 'foo', id: 'foo' });
expect(elb).toHaveBeenCalledTimes(0);

dataLayer.push({ event: 'bar', id: 'bar' });
expect(elb).toHaveBeenCalledWith(
expect.objectContaining({
id: 'bar',
}),
);
expect(elb).toHaveBeenCalledTimes(1);

dataLayer.push({ event: 'foo', id: 'bar' });
expect(elb).toHaveBeenCalledTimes(1);

processedEvents.delete('foo');
dataLayer.push({ event: 'foo', id: 'foo' });
expect(elb).toHaveBeenCalledTimes(2);

expect(processedEvents.has('foo')).toBeTruthy();
expect(processedEvents.has('bar')).toBeTruthy();
expect(processedEvents.size).toBe(2);
});

test('error handling', () => {
const mockOrg = jest.fn();
dataLayer.push = mockOrg;
Expand Down
6 changes: 1 addition & 5 deletions packages/sources/datalayer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function sourceDataLayer(
const { elb, prefix = 'dataLayer' } = partialConfig;
if (!elb) return;

let { dataLayer, processedEvents } = partialConfig;
let { dataLayer } = partialConfig;

// Ensure the dataLayer exists
if (!dataLayer) {
Expand All @@ -22,15 +22,11 @@ export function sourceDataLayer(
dataLayer = window[key] as DataLayer;
}

// Ensure the processedEvents exists
if (!processedEvents) processedEvents = new Set();

const config: Config = {
...partialConfig,
elb,
dataLayer,
prefix,
processedEvents,
};

// Process already existing events in the dataLayer
Expand Down
4 changes: 0 additions & 4 deletions packages/sources/datalayer/src/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ export function push(config: Config, ...args: unknown[]) {
if (command) {
config.elb(command.name, command.data as WalkerOS.PushData);
} else if (event) {
// Prevent duplicate events
if (config.processedEvents.has(event.id)) return;
config.processedEvents.add(event.id);

// Hand over to walker instance
config.elb(event);
}
Expand Down
1 change: 0 additions & 1 deletion packages/sources/datalayer/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export interface Config {
mapping?: Mapping;
name?: string;
prefix: string;
processedEvents: Set<string>;
}

export interface Mapping {
Expand Down

0 comments on commit e6a2e23

Please sign in to comment.