Skip to content

Commit

Permalink
fix: remove event emition from proxy iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
drusco committed Mar 24, 2024
1 parent a1c0f3d commit dd7fb6f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 26 deletions.
21 changes: 0 additions & 21 deletions src/utils/proxyIterator.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import ProxyNexo from "../lib/ProxyNexo.js";
import NexoTS from "../lib/types/Nexo.js";
import { proxyIterator } from "./index.js";
import map from "../lib/maps.js";

const nexo = new ProxyNexo();

Expand All @@ -17,23 +15,4 @@ describe("proxyIterator", () => {
expect(proxies.includes(foo)).toBe(true);
expect(proxies.includes(bar)).toBe(true);
});

it("Emits a deletion event when the proxy does not exists anymore", () => {
const proxy = nexo.createProxy();
const { id } = map.proxies.get(proxy);
const callback = jest.fn();

const weakRefMock = {
deref() {},
} as WeakRef<NexoTS.Proxy>;

nexo.entries.set(id, weakRefMock);
nexo.addListener("nx.delete", callback);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const proxies = [...proxyIterator(nexo)];

expect(callback).toHaveBeenCalledTimes(1);
expect(callback).toHaveBeenCalledWith(id);
});
});
8 changes: 3 additions & 5 deletions src/utils/proxyIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import ProxyNexo from "../lib/ProxyNexo.js";
const proxyIterator = function* (
scope: ProxyNexo,
): IterableIterator<Nexo.Proxy> {
for (const [id, ref] of scope.entries) {
for (const [, ref] of scope.entries) {
const proxy = ref.deref();
if (proxy) yield proxy;
else {
scope.entries.delete(id);
scope.emit("nx.delete", id);
if (proxy) {
yield proxy;
}
}
};
Expand Down

0 comments on commit dd7fb6f

Please sign in to comment.