Skip to content

Commit 2a8cec2

Browse files
committed
feat: use workers for streamListDiff
1 parent 4d22c68 commit 2a8cec2

17 files changed

+1927
-229
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ import { streamListDiff } from "@donedeal0/superdiff/client";
314314

315315
Streams the diff of two object lists, ideal for large lists and maximum performance.
316316

317+
ℹ️ `streamListDiff` requires ESM support. For browser usage, it will work out of the box if you use a modern bundler (Webpack, Rollup) or JavaScript framework (Next.js, Vue.js). For Node.js, just add `"type": "module"` in your package.json.
318+
317319
#### FORMAT
318320

319321
**Input**
@@ -344,7 +346,9 @@ Streams the diff of two object lists, ideal for large lists and maximum performa
344346
options: {
345347
showOnly?: ("added" | "deleted" | "moved" | "updated" | "equal")[], // [] by default
346348
chunksSize?: number, // 0 by default
347-
considerMoveAsUpdate?: boolean; // false by default
349+
considerMoveAsUpdate?: boolean, // false by default
350+
useWorker?: boolean // true by default
351+
348352
}
349353
```
350354

@@ -355,6 +359,7 @@ Streams the diff of two object lists, ideal for large lists and maximum performa
355359
- `chunksSize` the number of object diffs returned by each streamed chunk. (e.g. `0` = 1 object diff per chunk, `10` = 10 object diffs per chunk).
356360
- `showOnly` gives you the option to return only the values whose status you are interested in (e.g. `["added", "equal"]`).
357361
- `considerMoveAsUpdate`: if set to `true` a `moved` value will be considered as `updated`.
362+
- `useWorker`: if set to `true`, the diff will be run in a worker for maximum performance. Only recommended for large lists (e.g. +100,000 items).
358363

359364
**Output**
360365

jest.config.js renamed to jest.config.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
module.exports = {
1+
import type { Config } from "jest";
2+
3+
const config: Config = {
24
transform: {
3-
"^.+\\.(ts|js)$": [
5+
"^.+\\.(ts|js)$": [
46
"@swc/jest",
57
{
68
jsc: {
@@ -13,11 +15,14 @@ module.exports = {
1315
paths: {
1416
"@models/*": ["./src/models/*"],
1517
"@lib/*": ["./src/lib/*"],
16-
1718
},
1819
target: "esnext",
1920
},
2021
},
2122
],
2223
},
24+
testEnvironment: "node",
25+
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
2326
};
27+
28+
export default config;

jest.setup.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { TextEncoder, TextDecoder } from "util";
2+
3+
global.TextEncoder = TextEncoder;
4+
//@ts-expect-error - the TextDecoder is valid
5+
global.TextDecoder = TextDecoder;

0 commit comments

Comments
 (0)