mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
18 lines
368 B
TypeScript
18 lines
368 B
TypeScript
export class WeakArray<T extends object> {
|
|
private weakArray: WeakRef<T>[] = [];
|
|
|
|
constructor() {}
|
|
|
|
push(obj: T) {
|
|
this.weakArray.push(new WeakRef(obj));
|
|
}
|
|
|
|
forEach(callback: (obj: T, index: number) => void) {
|
|
this.weakArray.forEach((ref, index) => {
|
|
const obj = ref.deref();
|
|
if (obj) {
|
|
callback(obj, index);
|
|
}
|
|
});
|
|
}
|
|
} |