Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds reconcileWithKeys #2280

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix the simple starting test
  • Loading branch information
titoBouzout committed Sep 12, 2024
commit febb6035ce0ef0f25282b677c5dbffe58280f62f
75 changes: 66 additions & 9 deletions packages/solid/store/test/modifiers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,26 +366,83 @@ describe("modifyMutable with reconcile", () => {
});

describe("reconcileWithKeys", () => {
test("simple test", () => {
// this test should match next test
test("test 1 - expected regular behaviour", () => {
createRoot(() => {
const [target, setStore] = createStore({
c: [
{ idx: 1, name: "1" },
{ idx: 0, name: "0" }
]
c: {
a: [
{ ida: 1, name: "1" },
{ ida: 0, name: "0" }
],
b: [
{ idb: 1, name: "1" },
{ idb: 0, name: "0" }
]
}
});

const ref1 = target.c[1];
const ref = target.c.a[1];

const source = {
c: [{ idx: 0, name: "0 modified" }]
c: {
a: [{ ida: 0, name: "0 modified" }],
b: [{ idb: 0, name: "0 modified" }]
}
};

setStore("c", reconcile(source.c));
expect(target.c.a[0]).not.toBe(ref);

expect(target.c[0]).toBe(ref1);
expect(target).toEqual({
c: {
a: [{ ida: 0, name: "0 modified" }],
b: [{ idb: 0, name: "0 modified" }]
}
});
});
});
test("test 1 - expected reconcileWithKeys behaviour", () => {
createRoot(() => {
const [target, setStore] = createStore({
c: {
a: [
{ ida: 1, name: "1" },
{ ida: 0, name: "0" }
],
b: [
{ idb: 1, name: "1" },
{ idb: 0, name: "0" }
]
}
});

expect(target).toEqual({ c: [{ idx: 0, name: "0 modified" }] });
const ref = target.c.a[1];

const source = {
c: {
a: [{ ida: 0, name: "0 modified" }],
b: [{ idb: 0, name: "0 modified" }]
}
};

setStore(
"c",
reconcileWithKeys(source.c, {
keys: {
a: { _key: "ida" },
b: { _key: "idb" }
}
})
);
expect(target.c.a[0]).toBe(ref);

expect(target).toEqual({
c: {
a: [{ ida: 0, name: "0 modified" }],
b: [{ idb: 0, name: "0 modified" }]
}
});
});
});
});
Expand Down
Loading