-
Notifications
You must be signed in to change notification settings - Fork 177
code style #94
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
code style #94
Conversation
9681b39
to
15072b5
Compare
const sourcePath = join(sourceRoot, file); | ||
const outputPath = join(outputRoot, "_file", file); | ||
const stats = await getStats(sourcePath); | ||
const stats = await maybeStat(sourcePath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm used to seeing "maybe" on conditional updates, not on get/find method, and when it is used it seems like it should modify a verb-object, like "maybeCommit" or "maybeCommitNotebook". We're free to create whatever convention we want, but "maybeStat" and "maybeLoader" sound strange to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think “findLoader” is a fine name, and I’m happy to revert that back. The main thing is that I wanted it to return null or undefined instead of an empty object (because this provides a more obvious way of checking existence). And I think “find” reasonably implies that it can return null or undefined (like array.find).
For “maybe” stat, it’s for parity with the underlying stat method, which at least in my experience is often used as a verb, as in “stat’ing a file”. We’ve used the “maybe” pattern extensively in Plot, but mostly for parsing/normalize user input to some trusted representation. I like the “maybe” pattern here because it indicates conditionality: you might not get the stats returned.
stats: Stats; | ||
} | ||
|
||
export async function runLoader(commandPath: string, outputPath: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could really be any kind of command I suppose, not just a loader.
If we want the naming to be consistent, we could change "commandPath" to loaderPath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to make further changes here, I’d consider having findLoader return a Loader implementation with a run method. Then the caller would say loader.run instead of runLoader, and you wouldn’t have to pass in the command path again.
export async function runLoader(commandPath: string, outputPath: string) { | ||
if (runningCommands.has(commandPath)) return runningCommands.get(commandPath); | ||
const command = new Promise<void>((resolve, reject) => { | ||
const command = (async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these changes fix the bug that Fil saw with multiple FileAttachments calls for the same file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does! ref. #89 (comment) ; I've built the repro and can confirm that it crashes on main and doesn't crash with this branch.
15072b5
to
5cecc05
Compare
Async code review for some recent changes:
findLoader
tomaybeLoader
; return null instead of empty object to be more explicitjoin(root, path)
out ofmaybeLoader
and to the callerrunCommand
torunLoader
to consistency (in the future, consider a loader.run method?)async
function to avoid uncaught rejections inrunLoader
resolveDiffs
error
binding in try-catchurl.toString()
in
testIt looks like there aren’t any tests for data loaders yet? We should think about how we could add those. I haven’t tested the above changes (other than running the tests).