Add iterate, fix each method in mock container

This commit is contained in:
Sirz Benjie 2025-05-28 19:52:14 -05:00
parent d5789105f3
commit 70b74e143e
No known key found for this signature in database
GPG Key ID: 4A524B4D196C759E

View File

@ -272,9 +272,24 @@ export default class MockContainer implements MockGameObject {
return this; return this;
} }
each(method): this { // biome-ignore lint/complexity/noBannedTypes: This matches the signature of the method it mocks
each(callback: Function, context?: object, ...args: any[]): this {
if (context !== undefined) {
callback = callback.bind(context);
}
for (const item of this.list.slice()) {
callback(item, ...args);
}
return this;
}
// biome-ignore lint/complexity/noBannedTypes: This matches the signature of the method it mocks
iterate(callback: Function, context?: object, ...args: any[]): this {
if (context !== undefined) {
callback = callback.bind(context);
}
for (const item of this.list) { for (const item of this.list) {
method(item); callback(item, ...args);
} }
return this; return this;
} }