Skip to content

dev(doc): Align API modules and strengthen Connect/registry contract …#48

Merged
karim-semmoud merged 2 commits into
mainfrom
chore/api-modules-contract-tests
Jun 1, 2026
Merged

dev(doc): Align API modules and strengthen Connect/registry contract …#48
karim-semmoud merged 2 commits into
mainfrom
chore/api-modules-contract-tests

Conversation

@karim-semmoud

Copy link
Copy Markdown
Member

Summary

Aligns imperative API documentation patterns, removes duplicated TreeView API implementations, and adds ExUnit contract tests so registry ↔ Connect ↔ hook wiring stays consistent. Moduledoc Flagpack examples now use String.to_existing_atom/1 instead of String.to_atom/1; e2e demo snippets were updated to match doc parity.

Changes

lib/components/tree_view.ex

  • Imperative API (set_expanded_value, set_selected_value, value, expanded_value) delegates to Corex.TreeView.Api instead of duplicating JS.dispatch / push_event in the component module
  • value / expanded_value use thin wrappers where arity or guards differ from Api

lib/components/accordion.ex

  • Added import Corex.Api.Doc
  • Replaced 8 raw @doc type: :api blocks with api_doc(...) / """) (same pattern as other components)

Moduledoc examples (String.to_existing_atom)

  • lib/components/select.ex
  • lib/components/combobox.ex
  • lib/components/listbox.ex

E2e doc parity

  • e2e/lib/e2e_web/demos/select_demo.ex (extended_code, extended_grouped_code)
  • e2e/lib/e2e_web/demos/combobox_demo.ex (extended_code, extended_grouped_code)

Tests

  • test/corex/api_modules_contract_test.exs: no raw @doc type: :api; API modules use Corex.Api.Doc or Corex.Api.Imports; Checkbox/TreeView delegate set_* to *.Api
  • test/corex/connect_registry_contract_test.exs: hooked components have loadable connect_module with props/1 or group/1 (Toast); naming convention Corex.<Component>.Connect; wire JSON ids match registry

Why

Checkbox already split imperative API into *.Api + defdelegate; TreeView had a full duplicate in tree_view.ex and tree_view/api.ex. Accordion was the only component still using hand-written @doc type: :api. Contract tests catch registry/Connect drift early (complements existing hooks export and Vitest contract tests). Moduledoc String.to_atom on user-controlled values is a footgun; examples now show the safer pattern.

Breaking changes

None. Public API and runtime behavior unchanged.

Test plan

  • mix test test/corex/api_modules_contract_test.exs test/corex/connect_registry_contract_test.exs
  • mix lint (doc parity 25/25, Credo, Sobelow)
  • Manual: TreeView API demos (set expanded/selected, read value) on e2e site

@karim-semmoud karim-semmoud self-assigned this Jun 1, 2026
@karim-semmoud karim-semmoud merged commit f57cce8 into main Jun 1, 2026
14 checks passed
@karim-semmoud karim-semmoud deleted the chore/api-modules-contract-tests branch June 1, 2026 13:11
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.

1 participant