refactor(js): delegate compatible promise ops to gleam_javascript (#12) - #22
Merged
Merged
Conversation
Route resolve, then_, map, all, race, and await_ through gleam/javascript/promise instead of handwritten JavaScript. Retain minimal FFI adapters only for reject (Error-wrapping rejection construction) and catch_ (Promise-returning recovery), which the package cannot express while preserving the current contract. Add async tests covering resolve, mapping, Promise-returning chaining, ordered all, race (including first-rejection), Error-surfacing rejection, Promise-returning recovery, and one-shot await_ callbacks. Public API (names, labels, types) is unchanged; the facade preserves the existing surface. Closes #12.
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #12. Delegates the compatible
glendix/js/promiseoperations togleam/javascript/promiseand removes their duplicate handwritten JavaScript,keeping only the two adapters the package cannot express.
Changes
src/glendix/js/promise.gleam—resolve,then_,map,all,race,and
await_now delegate togleam/javascript/promise(resolve,await,map,await_list,race_list, andmaprespectively).rejectandcatch_remain thin facades over retained FFI adapters, each documentedin-source. Stale externals removed.
src/glendix/js/promise_ffi.mjs— trimmed to onlypromise_reject(Error-wrapping rejection construction) and
promise_catch(Promise-returningrecovery); dropped the now-unused
toListimport and six duplicate functions.test/glendix_test.gleam/test/glendix_test_ffi.mjs— added asynctests for resolve, mapping, Promise-returning chaining, ordered
all,race(first-fulfilled and first-rejection), Error-surfacing rejection,
Promise-returning recovery, fulfilled pass-through, and one-shot
await_.Design decisions
reject:gleam_javascripthas no rejection constructor and the reason mustsurface as a JavaScript
Error, so a minimal adapter stays.catch_:promise.rescuerecovers with a plain value; it cannot preservethis helper's Promise-returning recovery, opaque
PromiseRejection, or nativecatchflattening, so a minimal adapter stays.refactor, so no migration docs or semver bump are required.
glendix -> mendrawkeeps its declared Hex source form.Acceptance criteria
all,race, rejection, Promise-returning recovery, and one-shotawait_Errorvaluesglendix -> mendrawretains its declared dependency source formVerification
Run against the isolated worktree/commit:
gleam format --check,gleam check,gleam build --warnings-as-errors,gleam docs build— passgleam test --runtime bun— 37 passed, no failurescheck-style.py,check-ffi-contracts.py— passdependency-mode.sh check-commit glendix— valid