Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanatkn committed Feb 16, 2024
1 parent ca361b5 commit 3f44003
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/lib/fs_fetch_value_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {exists} from '@ryanatkn/gro/fs.js';
import {dirname, join} from 'node:path';
import {paths} from '@ryanatkn/gro/paths.js';
import {format_file} from '@ryanatkn/gro/format_file.js';
import {dequal} from 'dequal';
import {deserialize_cache, serialize_cache, type Fetch_Value_Cache} from '@ryanatkn/belt/fetch.js';

// TODO upstream to Gro probably, and rename/redesign?
Expand Down Expand Up @@ -39,7 +38,7 @@ export const create_fs_fetch_value_cache = async (
name,
data,
save: async () => {
if (dequal(initial, data)) {
if (deep_equal_maps(initial, data)) {
return false; // no changes to save
}
await mkdir(dirname(data_path), {recursive: true});
Expand All @@ -48,3 +47,16 @@ export const create_fs_fetch_value_cache = async (
},
};
};

// TODO this is quick and dirty, but fine because it's only expected to be called during development
const deep_equal_maps = (a: Map<unknown, unknown>, b: Map<unknown, unknown>): boolean => {
if (a.size !== b.size) {
return false;
}
for (const [key, value] of a) {
if (!b.has(key) || JSON.stringify(b.get(key)) !== JSON.stringify(value)) {
return false;
}
}
return true;
};

0 comments on commit 3f44003

Please sign in to comment.