dsherret / dsherret/dax

Functionality for checking if external changes have occurred since the last time some code was run

Open
#116 0 comments 4 reactions 0 assignees View on GitHub
suggestion
Dominant language
TypeScript
Stars
1.5k
Forks
42
Avg merge
11m
Merged PRs (30d)
2

Description

It might be neat to have an API that can be used to tell if some external changes have occurred since the last time a command was run. This would be useful for not doing an action if unnecessary to do so.

```ts
const tracker = $.changeTracker(import.meta, "data files"); // cache keyed on this current file and a string

tracker.addMtime("data/file1.json"); // hashes based on the file path's last modified time
tracker.addPath("data/file2.json"); // hashes based on the file path's content
tracker.addMtime("some_dir"); // hashes based on the descendants mtime
tracker.addPath("some_dir"); // hashes based on the descendants contents
tracker.addValue(123456); // hashes a specific value, which could have a source anywhere else

// multiple paths or values
tracker.addPaths(paths);
tracker.addMTimes(otherPaths);
tracker.addValues(values);

// will always run if the output path doesn't exist
tracker.addOutputPath("output/data.json");

// run if changed
if (tracker.hasChangedSync()) {
await doStuff();
tracker.commitSync();
}

// or as a single call
await tracker.runIfChanged(async () => {
await doStuff();
});

// builder pattern
await $.changeTracker(import.meta, "data files")
.addPaths(paths)
.addOutputPath("output/data.json")
.runIfChanged(async () => {
await createOutputDataJsonFile();
});
```

The hash could be saved in local storage.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.