Skip to content

Return object with reset function from useUpdateFragment - #221

Merged
jho406 merged 3 commits into
thoughtbot:v2from
daniel-frampton-pc:df214-add-undo-redo-reset-chain-to-use-update-fragment
Jul 15, 2026
Merged

jho406 merged 3 commits into
thoughtbot:v2from
daniel-frampton-pc:df214-add-undo-redo-reset-chain-to-use-update-fragment

Conversation

@daniel-frampton-pc

Copy link
Copy Markdown
Contributor

What

  • Return an object from useUpdateFragment with a function property to reset to original state.
  • Renames the associated spec file to match the recently renamed hook.
  • Adds unit tests for the new reset behavior.

Contributes to, but does not fully resolve, #214 (split off just the reset behavior, still need redo and undo behavior).

How

  • Modified the return type of all three setters to expect the new object with reset function.
  • Create a reset function within the setter which locks in a dispatch to update the fragment to its original, pre-update state.
  • Return object with that reset function as its only property.

AI Disclaimer

I made the change to the hook by hand and chose what kinds of tests to add, but I utilized Claude Code to generate the unit tests themselves (for speed, during the Ruby Conf '26 hack day). I reviewed them in detail and they do what I want them to.

When checking to see if there was an existing test file for useUpdateFragment, we found that tests exists but were in a spec file whose name had not yet been updated to reflect the recently changed name of the hook.
…ginal state.

This simplifies the developer experience in the scenario where an update is dispatched and needs to be rolled back (as in the case of optimistic UI patterns).

An object is returned so that it can be expanded later to also include redo and undo functions, as described in issue thoughtbot#214.
@jho406
jho406 merged commit f6344f6 into thoughtbot:v2 Jul 15, 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.

2 participants