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

Inline guard in api.ts #64

Merged
merged 14 commits into from
Jan 17, 2025
Merged

Inline guard in api.ts #64

merged 14 commits into from
Jan 17, 2025

Conversation

lynn
Copy link
Contributor

@lynn lynn commented Jan 9, 2025

I think this is a case where duplication is cheaper than the wrong abstraction. Not that guard() is wrong per se, but explicitly writing out each check will make the API functions easier to type (in the TypeScript sense) and easier to follow (less "callback hell" / it's completely clear what gets checked where in what order).

This will also help turn this file into a (testable!) ToaduaApi class. Right now checks.goodid depends on index_of which depends on store which is a global. Eventually it'll want to be something like this.goodid which uses this.store. And this refactor will be easier to reason about without having to deal with the overly-abstract guard.

For now, I've just tried to mechanically repace every entry like:

    body: checks.nobomb,

with a simple if-return like:

    const (e_body) = checks.nobomb(i.body);
    if (e_body !== true) return ret(flip(`invalid field 'body': ${e_body}`));

Hopefully, this sets up a future PR to get rid of ret() and completely eliminate the continuation-passing style from the API.

@lynn lynn requested a review from uakci January 9, 2025 14:21
core/commons.ts Show resolved Hide resolved
core/api.ts Show resolved Hide resolved
Copy link
Collaborator

@uakci uakci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good, thanks for the contribution =:3!

@uakci uakci merged commit 4e4da0e into main Jan 17, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants