Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose setHistories and setHistoryIndex #525

Merged
merged 8 commits into from
Jul 23, 2024

Conversation

mkilpatrick
Copy link
Contributor

This addresses #519.

This change exposes the history store's setHistories and setHistoryIndex functions. When they are called the data is dispatched so that Puck rerenders. The use case this supports is when a Puck consumer wants to change or reset the history state manually without requiring the page to be refreshed.

Copy link

vercel bot commented Jul 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
puck-demo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 20, 2024 9:57am
puck-docs ✅ Ready (Inspect) Visit Preview Jul 20, 2024 9:57am

Copy link

vercel bot commented Jul 1, 2024

@mkilpatrick is attempting to deploy a commit to the Measured Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Member

@chrisvxd chrisvxd left a comment

Choose a reason for hiding this comment

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

Great stuff again! Left a few comments.

apps/docs/pages/docs/api-reference/functions/use-puck.mdx Outdated Show resolved Hide resolved
apps/docs/pages/docs/api-reference/functions/use-puck.mdx Outdated Show resolved Hide resolved
apps/docs/pages/docs/api-reference/functions/use-puck.mdx Outdated Show resolved Hide resolved
packages/core/lib/use-puck-history.ts Show resolved Hide resolved
mkilpatrick and others added 3 commits July 19, 2024 12:33
Co-authored-by: Chris Villa <chrisvxd@users.noreply.github.com>
Co-authored-by: Chris Villa <chrisvxd@users.noreply.github.com>
Co-authored-by: Chris Villa <chrisvxd@users.noreply.github.com>
Copy link
Member

@chrisvxd chrisvxd left a comment

Choose a reason for hiding this comment

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

Bravo

act(() => renderedHook.result.current.record("Oranges"));
act(() => renderedHook.result.current.setHistoryIndex(0));

expect(renderedHook.result.current.hasPast).toBe(true);
Copy link
Member

Choose a reason for hiding this comment

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

I'm trying to full remember the functionality of hasPast.

This test (and some of the ones I wrote) read to me like hasPast should be false when you're at index 0, but they're all asserting it to be true.

This is nothing wrong with your tests, but just making a note for myself to think about.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

-1 is the no history index

@chrisvxd chrisvxd merged commit 39e7f40 into measuredco:main Jul 23, 2024
4 checks passed
@mkilpatrick mkilpatrick deleted the expose-sethistory branch September 20, 2024 14:22
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