Skip to content

feat: add withResizeObserver reusable - #17

Open
Guria wants to merge 1 commit into
mainfrom
feat/with-resize-observer
Open

feat: add withResizeObserver reusable#17
Guria wants to merge 1 commit into
mainfrom
feat/with-resize-observer

Conversation

@Guria

@Guria Guria commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

Adds withResizeObserver — an extension for Atom<HTMLElement | null> that adds a sizeEntry computed exposing the latest ResizeObserverEntry for the current element.

  • Lazy: the observer is created per element via memo + reatomObservable only while sizeEntry is connected, and disconnects automatically on element change/disconnect.
  • Extracted from a production app (guria/modern-stack src/shared/reatom/resize-observer.ts) where it backs responsive component measurements.
  • Browser tests (headless chromium) cover initial measurement, resize updates, null element, switching elements, and trace naming.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings July 12, 2026 21:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a new Reatom extension withResizeObserver for Atom<HTMLElement | null> that exposes the latest ResizeObserverEntry via a lazy .sizeEntry computed, along with docs, an example, browser tests, and registry metadata to publish it as a reusable.

Changes:

  • Added withResizeObserver() extension that wires an HTMLElement | null atom to a lazily-connected ResizeObserver.
  • Added documentation, example usage, and headless-browser test coverage for observation behavior and computed naming.
  • Registered the reusable in registry.json and via a jsrepo meta descriptor.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/reusables/resize-observer/with-resize-observer.ts Implements the withResizeObserver extension and .sizeEntry computed.
src/reusables/resize-observer/with-resize-observer.meta.ts Declares registry metadata for the reusable and its doc/test/example files.
src/reusables/resize-observer/with-resize-observer.md Documents API, behavior, and usage example.
src/reusables/resize-observer/with-resize-observer.example.ts Provides a minimal usage example for the extension.
src/reusables/resize-observer/with-resize-observer.browser.test.ts Adds browser tests covering resize updates, null target, element switching, and naming.
registry.json Registers withResizeObserver as a new reatom:extension entry and its associated files.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +41 to +51
subscribe: (set) => {
const observer = new ResizeObserver(
wrap((entries) => {
set(entries.find((entry) => entry.target === node))
}),
)

observer.observe(node)

return () => observer.disconnect()
},
Add a ResizeObserver extension with docs, browser tests, example, and registry entry.
@Guria
Guria force-pushed the feat/with-resize-observer branch from ff7db0b to aa25369 Compare July 13, 2026 23:48
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