[go: nahoru, domu]

Skip to content

Commit

Permalink
test async producers with patches
Browse files Browse the repository at this point in the history
  • Loading branch information
giusepperaso committed Apr 8, 2023
1 parent 5133703 commit e2a3bd8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/core/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ export function convertPatchesToStandard(
return converted;
}

// internal function to build string paths in standard patches
// we use a more complicated version instead of a simple join to allow "" as index in string version
function __stdBuildStringPath(newPath: unknown[]) {
// we use a more complicated version to allow "" as index in string version
let ret = "";
for (let i = 0; i !== newPath.length; i++) {
const p = newPath[i];
Expand Down
18 changes: 17 additions & 1 deletion src/tests/integration/patches.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { expect, it } from "vitest";
import { applyPatches, Patch, produceWithPatches } from "../..";
import {
applyPatches,
asyncProduceWithPatches,
Patch,
produceWithPatches,
} from "../..";
import { runMultiple } from "./utils";

runMultiple("test patch production", () => {
Expand Down Expand Up @@ -173,4 +178,15 @@ runMultiple("test patch production", () => {
expect(patches[0].v).toBe(4);
expect(rev[0].v).toBe(2);
});
it("works with async producers with patches", async () => {
const [result, patches, reverse] = await asyncProduceWithPatches(
{ n: 1 },
async (draft) => {
draft.n = 2;
}
);
expect(result.n).toBe(2);
expect(Array.isArray(patches)).toBe(true);
expect(Array.isArray(reverse)).toBe(true);
});
});

0 comments on commit e2a3bd8

Please sign in to comment.