diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e04398..a77a636 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ # Upcoming +- Performance: Better handling of wait timeouts. Instead of waiting in intervals of 50ms, we check the result whenever new results are + added to the bin. +- Feature: "clear" method to remove all objects + # v0.2.1 Date: 2024-04-21T21:47:25.224Z diff --git a/src/QueryBin.d.ts b/src/QueryBin.d.ts index 78146bb..24331e9 100644 --- a/src/QueryBin.d.ts +++ b/src/QueryBin.d.ts @@ -5,6 +5,8 @@ export class QueryBin = QueryDefinitions> { addAll(values: T[]): void; + clear(): void; + all(): T[]; queryAll: QueryAll; diff --git a/src/QueryBin.js b/src/QueryBin.js index 998074b..a1f3f00 100644 --- a/src/QueryBin.js +++ b/src/QueryBin.js @@ -77,6 +77,10 @@ export class QueryBin { this.latch.next(); } + clear() { + this.values = []; + } + all() { return this.values; } diff --git a/src/QueryBin.test.ts b/src/QueryBin.test.ts index db94c86..c4a0eec 100644 --- a/src/QueryBin.test.ts +++ b/src/QueryBin.test.ts @@ -31,6 +31,14 @@ describe("QueryBin", () => { expect(numbers.all()).toEqual([1, 2, 3, 1, 2]); }); + it("can clear all values", () => { + const numbers = new QueryBin({}); + numbers.addAll([1, 2, 3]); + expect(numbers.all()).toEqual([1, 2, 3]); + numbers.clear(); + expect(numbers.all()).toEqual([]); + }); + it("queryAll returns all results matching a query", () => { const bin = new QueryBin({ dividableBy }); bin.addAll([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);