Skip to content

Commit a87e257

Browse files
committed
Set comparison added in 1.1.0 wasn't fully functional.
Additional fix for #194.
1 parent 4caba25 commit a87e257

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ Headlines: Added, Changed, Deprecated, Removed, Fixed, Security
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.1.1] - 2023-06-20
9+
10+
### Fixed
11+
12+
- Set comparison added in 1.1.0 wasn't fully functional.
13+
814
## [1.1.0] - 2023-06-20
915

1016
### Added
1117

12-
- Support for `Set` in schemas, using `z.set()`.
18+
- Support for `Set` in schemas, using `z.set()`. ([#194](https://github.com/ciscoheat/sveltekit-superforms/issues/194))
1319

1420
### Fixed
1521

src/lib/traversal.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,13 @@ export async function traversePathsAsync<
190190
}
191191
}
192192

193+
// Thanks to https://stackoverflow.com/a/31129384/70894
194+
function eqSet(xs: Set<unknown>, ys: Set<unknown>) {
195+
return (
196+
xs === ys || (xs.size === ys.size && [...xs].every((x) => ys.has(x)))
197+
);
198+
}
199+
193200
/**
194201
* Compare two objects and return the differences as paths.
195202
*/
@@ -219,7 +226,7 @@ export function comparePaths(newObj: unknown, oldObj: unknown) {
219226
exists &&
220227
data.value instanceof Set &&
221228
exists.value instanceof Set &&
222-
data.value !== exists.value
229+
!eqSet(data.value, exists.value)
223230
) {
224231
addDiff();
225232
}

src/routes/tests/issue-194/+page.svelte

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@
1919
<button
2020
type="button"
2121
on:click={() =>
22-
form.update(
23-
($form) => {
24-
$form.things.add(1);
25-
return $form;
26-
},
27-
{ taint: { fields: 'things' } }
28-
)}>Add 1</button
22+
form.update(($form) => {
23+
$form.things.add(1);
24+
return $form;
25+
})}>Add 1</button
2926
>
3027
<button
3128
type="button"

0 commit comments

Comments
 (0)