Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate collections.forEach #152132

Merged
merged 1 commit into from Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 8 additions & 11 deletions src/vs/base/common/collections.ts
Expand Up @@ -33,18 +33,15 @@ export function values<T>(from: IStringDictionary<T> | INumberDictionary<T>): T[
}

/**
* Iterates over each entry in the provided dictionary. The iterator allows
* to remove elements and will stop when the callback returns {{false}}.
* Iterates over each entry in the provided dictionary. The iterator will stop when the callback returns `false`.
*
* @deprecated Use `Object.entries(x)` with a `for...of` loop.
*/
export function forEach<T>(from: IStringDictionary<T> | INumberDictionary<T>, callback: (entry: { key: any; value: T }, remove: () => void) => any): void {
for (const key in from) {
if (hasOwnProperty.call(from, key)) {
const result = callback({ key: key, value: (from as any)[key] }, function () {
delete (from as any)[key];
});
if (result === false) {
return;
}
export function forEach<T>(from: IStringDictionary<T> | INumberDictionary<T>, callback: (entry: { key: any; value: T }) => any): void {
for (const [key, value] of Object.entries(from)) {
const result = callback({ key, value });
if (result === false) {
return;
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/vs/base/test/common/collections.test.ts
Expand Up @@ -24,9 +24,6 @@ suite('Collections', () => {

collections.forEach(dict, () => false);

collections.forEach(dict, (x, remove) => remove());
assert.strictEqual(dict['toString'], undefined);

// don't iterate over properties that are not on the object itself
const test = Object.create({ 'derived': true });
collections.forEach(test, () => assert(false));
Expand Down