diff --git a/packages/suspense-website/src/examples/createIntervalCache/cacheWithBigIntInterval.ts b/packages/suspense-website/src/examples/createIntervalCache/cacheWithBigIntInterval.ts deleted file mode 100644 index 65ab2df..0000000 --- a/packages/suspense-website/src/examples/createIntervalCache/cacheWithBigIntInterval.ts +++ /dev/null @@ -1,17 +0,0 @@ -const getPointForValue = (value: any) => null as any; -const load = async (start: any, end: any) => null as any; - -type Value = any; - -// REMOVE_BEFORE - -import { compare } from "extra-bigint"; -import { createIntervalCache } from "suspense"; - -type Point = bigint; - -createIntervalCache({ - load, - comparePoints: compare, - getPointForValue, -}); diff --git a/packages/suspense-website/src/examples/index.ts b/packages/suspense-website/src/examples/index.ts index 1b4a290..7a5bbab 100644 --- a/packages/suspense-website/src/examples/index.ts +++ b/packages/suspense-website/src/examples/index.ts @@ -97,12 +97,6 @@ const createIntervalCache = { cache: processExample( readFileSync(join(__dirname, "createIntervalCache", "cache.ts"), "utf8") ), - cacheWithBigIntInterval: processExample( - readFileSync( - join(__dirname, "createIntervalCache", "cacheWithBigIntInterval.ts"), - "utf8" - ) - ), cacheWithPartialResults: processExample( readFileSync( join(__dirname, "createIntervalCache", "cacheWithPartialResults.ts"), diff --git a/packages/suspense-website/src/routes/api/createIntervalCache.tsx b/packages/suspense-website/src/routes/api/createIntervalCache.tsx index 6e5b781..b8a447e 100644 --- a/packages/suspense-website/src/routes/api/createIntervalCache.tsx +++ b/packages/suspense-website/src/routes/api/createIntervalCache.tsx @@ -16,10 +16,17 @@ export default function Route() {

An "interval cache" is a specialized cache that incrementally loads - and merges sets of values over time. + and merges sets of values over time. Values are loaded for "intervals" + which are a range of either numbers (or{" "} + + + BigInts + + + )

- An example of this is{" "} + An example of an interval cache can be found in{" "} Replay.io which fetches console logs for the region of a recording a user has "focused" on. If the user changes the focused region, additional logs @@ -41,29 +48,6 @@ export default function Route() {

- - -

- Points in an interval are typically numbers (e.g. 1, 3.5) but they can - also be{" "} - - - BigInts - - - . In that case a custom comparison function should be provided. -

-

- Here is an example using the NPM package{" "} - - - extra-bigint - - - : -

- -

diff --git a/packages/suspense/CHANGELOG.md b/packages/suspense/CHANGELOG.md index 9184a1e..15e1643 100644 --- a/packages/suspense/CHANGELOG.md +++ b/packages/suspense/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 0.0.36 +* `createIntervalCache` removes `comparePoints` param (as it is no longer needed). + ## 0.0.35 * `createIntervalCache` supports partial results via new options parameter `options.returnAsPartial(resultsArray)`. * `createIntervalCache` methods `getValue` and `getStatus` better handle sub-regions of already-loaded intervals. diff --git a/packages/suspense/package.json b/packages/suspense/package.json index 1e6a08e..af41760 100644 --- a/packages/suspense/package.json +++ b/packages/suspense/package.json @@ -1,6 +1,6 @@ { "name": "suspense", - "version": "0.0.35", + "version": "0.0.36", "description": "Utilities for working with React suspense", "author": "Brian Vaughn ", "license": "MIT", diff --git a/packages/suspense/src/cache/createIntervalCache/createIntervalCache.test.ts b/packages/suspense/src/cache/createIntervalCache/createIntervalCache.test.ts index 82ac291..cbfa689 100644 --- a/packages/suspense/src/cache/createIntervalCache/createIntervalCache.test.ts +++ b/packages/suspense/src/cache/createIntervalCache/createIntervalCache.test.ts @@ -126,37 +126,40 @@ describe("createIntervalCache", () => { }); describe("configuration", () => { - it("should support bigint points via a custom comparePoints", async () => { - const comparePoints = jest.fn(compareBigInt); - + it("should support bigint points", async () => { const load = jest.fn(); load.mockImplementation((start: number, end: number, id: string) => [ start, ]); const bigIntCache = createIntervalCache({ - comparePoints, getPointForValue: (value) => value, load, }); - await bigIntCache.readAsync(BigInt("2"), BigInt("4"), "test"); - - expect(comparePoints).toHaveBeenCalled(); + await bigIntCache.readAsync( + BigInt("10000000000000000000000000000000002"), + BigInt("10000000000000000000000000000000004"), + "test" + ); expect(load).toHaveBeenCalledTimes(1); expect(load).toHaveBeenCalledWith( - BigInt("2"), - BigInt("4"), + BigInt("10000000000000000000000000000000002"), + BigInt("10000000000000000000000000000000004"), "test", expect.anything() ); - await bigIntCache.readAsync(BigInt("3"), BigInt("7"), "test"); + await bigIntCache.readAsync( + BigInt("10000000000000000000000000000000003"), + BigInt("10000000000000000000000000000000007"), + "test" + ); expect(load).toHaveBeenCalledTimes(2); expect(load).toHaveBeenCalledWith( - BigInt("4"), - BigInt("7"), + BigInt("10000000000000000000000000000000004"), + BigInt("10000000000000000000000000000000007"), "test", expect.anything() ); diff --git a/packages/suspense/src/cache/createIntervalCache/createIntervalCache.ts b/packages/suspense/src/cache/createIntervalCache/createIntervalCache.ts index 24dbcd4..297e93a 100644 --- a/packages/suspense/src/cache/createIntervalCache/createIntervalCache.ts +++ b/packages/suspense/src/cache/createIntervalCache/createIntervalCache.ts @@ -14,7 +14,6 @@ import { } from "../../constants"; import { IntervalCacheLoadOptions, - ComparisonFunction, GetPointForValue, PendingRecord, IntervalCache, @@ -72,7 +71,6 @@ export function createIntervalCache< Params extends Array, Value >(options: { - comparePoints?: ComparisonFunction; debugLabel?: string; getKey?: (...params: Params) => string; getPointForValue: GetPointForValue; @@ -83,7 +81,6 @@ export function createIntervalCache< ) => PromiseLike> | ValuesArray; }): IntervalCache { const { - comparePoints = defaultComparePoints, debugLabel, getKey = defaultGetKey, getPointForValue, @@ -766,6 +763,6 @@ export function createIntervalCache< }; } -function defaultComparePoints(a: any, b: any): number { - return a - b; +function comparePoints(a: any, b: any): number { + return Number(a - b); }