Skip to content

refactor(js): delegate compatible promise ops to gleam_javascript (#12) - #22

Merged
GG-O-BP merged 1 commit into
mainfrom
refactor/promise-ffi-gleam-javascript-issue-12
Sep 7, 2026
Merged

refactor(js): delegate compatible promise ops to gleam_javascript (#12)#22
GG-O-BP merged 1 commit into
mainfrom
refactor/promise-ffi-gleam-javascript-issue-12

Conversation

@GG-O-BP

@GG-O-BP GG-O-BP commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Closes #12. Delegates the compatible glendix/js/promise operations to
gleam/javascript/promise and removes their duplicate handwritten JavaScript,
keeping only the two adapters the package cannot express.

Changes

  • src/glendix/js/promise.gleamresolve, then_, map, all, race,
    and await_ now delegate to gleam/javascript/promise (resolve, await,
    map, await_list, race_list, and map respectively). reject and
    catch_ remain thin facades over retained FFI adapters, each documented
    in-source. Stale externals removed.
  • src/glendix/js/promise_ffi.mjs — trimmed to only promise_reject
    (Error-wrapping rejection construction) and promise_catch (Promise-returning
    recovery); dropped the now-unused toList import and six duplicate functions.
  • test/glendix_test.gleam / test/glendix_test_ffi.mjs — added async
    tests 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_javascript has no rejection constructor and the reason must
    surface as a JavaScript Error, so a minimal adapter stays.
  • catch_: promise.rescue recovers with a plain value; it cannot preserve
    this helper's Promise-returning recovery, opaque PromiseRejection, or native
    catch flattening, so a minimal adapter stays.
  • Public API (names, labels, types) is unchanged — non-breaking internal
    refactor, so no migration docs or semver bump are required.
  • glendix -> mendraw keeps its declared Hex source form.

Acceptance criteria

  • Every helper is mapped to a package primitive or documents a retained adapter
  • Compatible operations no longer have duplicate handwritten JS
  • Tests cover resolve, mapping, chaining, ordered all, race, rejection, Promise-returning recovery, and one-shot await_
  • Rejected string messages still surface as JavaScript Error values
  • No public API change (no migration/semver treatment needed)
  • FFI contract checks report no stale external declarations or exports
  • glendix -> mendraw retains its declared dependency source form

Verification

Run against the isolated worktree/commit:

  • gleam format --check, gleam check, gleam build --warnings-as-errors, gleam docs build — pass
  • gleam test --runtime bun37 passed, no failures
  • check-style.py, check-ffi-contracts.py — pass
  • dependency-mode.sh check-commit glendix — valid

Note: the shared/final family E2E tier operates on the primary working trees
(currently an unrelated feature branch) and cross-repo browser/Mendix
harnesses; it was not run from this isolated worktree, which has no downstream
consumers of this facade.

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.
@GG-O-BP
GG-O-BP merged commit 6084eaa into main Sep 7, 2026
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.

[ffi] Delegate compatible promise operations to gleam_javascript

1 participant