Skip to content

Commit

Permalink
refactor(core): Use a Set for deletedProperties in AugmentObject
Browse files Browse the repository at this point in the history
…(no-changelog) (#7131)
  • Loading branch information
netroy authored Sep 7, 2023
1 parent 7b49cf2 commit 67aaad1
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions packages/workflow/src/AugmentObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ export function augmentObject<T extends object>(data: T): T {
if (augmentedObjects.has(data)) return data;

const newData = {} as IDataObject;
const deletedProperties: Array<string | symbol> = [];
const deletedProperties = new Set<string | symbol>();

const proxy = new Proxy(data, {
get(target, key: string, receiver): unknown {
if (deletedProperties.indexOf(key) !== -1) {
if (deletedProperties.has(key)) {
return undefined;
}

Expand All @@ -107,7 +107,7 @@ export function augmentObject<T extends object>(data: T): T {
delete newData[key];
}
if (key in target) {
deletedProperties.push(key);
deletedProperties.add(key);
}

return true;
Expand All @@ -118,34 +118,33 @@ export function augmentObject<T extends object>(data: T): T {
delete newData[key];
}
if (key in target) {
deletedProperties.push(key);
deletedProperties.add(key);
}
return true;
}

newData[key] = newValue as IDataObject;

const deleteIndex = deletedProperties.indexOf(key);
if (deleteIndex !== -1) {
deletedProperties.splice(deleteIndex, 1);
if (deletedProperties.has(key)) {
deletedProperties.delete(key);
}

return true;
},
has(target, key) {
if (deletedProperties.indexOf(key) !== -1) return false;
if (deletedProperties.has(key)) return false;
return Reflect.has(newData, key) || Reflect.has(target, key);
},
ownKeys(target) {
const originalKeys = Reflect.ownKeys(target);
const newKeys = Object.keys(newData);
return [...new Set([...originalKeys, ...newKeys])].filter(
(key) => deletedProperties.indexOf(key) === -1,
(key) => !deletedProperties.has(key),
);
},

getOwnPropertyDescriptor(target, key) {
if (deletedProperties.indexOf(key) !== -1) return undefined;
if (deletedProperties.has(key)) return undefined;
return Object.getOwnPropertyDescriptor(key in newData ? newData : data, key);
},
});
Expand Down

0 comments on commit 67aaad1

Please sign in to comment.