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(archive): implement archive API #1

Merged
merged 1 commit into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ yarn add use-travel mutative

### API

You can use `useTravel` to create a time travel state. And it returns a tuple with the current state, the state setter, and the controls. The controls include `back`, `forward`, `reset`, `canBack`, `canForward`, `getHistory`, `patches`, `position`, and `go`.
You can use `useTravel` to create a time travel state. And it returns a tuple with the current state, the state setter, and the controls. The controls include `back`, `forward`, `reset`, `canBack`, `canForward`, `getHistory`, `patches`, `position`, `archive`, and `go`.

```jsx
import { useTravel } from 'use-travel';
Expand Down Expand Up @@ -82,26 +82,24 @@ const App = () => {
| ---------------- | ------------- | ------------------------------------- | -------------------------------- |
| `maxHistory` | number | The maximum number of history to keep | 10 |
| `initialPatches` | TravelPatches | The initial patches | {patches: [],inversePatches: []} |
| `autoArchive` | boolean | Auto archive the state | true |

### Return

| Return | type | description |
| --------------------- | -------------------------- | ------------------------------------------------------------------ |
| `state` | T | The current state |
| `setState` | Dispatch<T> | The state setter, support mutation update or return immutable data |
| `controls.back` | () => void | Go back to the previous state |
| `controls.forward` | () => void | Go forward to the next state |
| `controls.reset` | () => void | Reset the state to the initial state |
| `controls.canBack` | () => boolean | Check if can go back to the previous state |
| `controls.canForward` | () => boolean | Check if can go forward to the next state |
| `controls.getHistory` | () => T[] | Get the history of the state |
| `controls.patches` | TravelPatches[] | Get the patches history of the state |
| `controls.position` | number | Get the current position of the state |
| `controls.go` | (position: number) => void | Go to the specific position of the state |

### TODO

- [ ] add `archive` functionality
| Return | type | description |
| --------------------- | -------------------------- | ---------------------------------------------------------------------- |
| `state` | T | The current state |
| `setState` | Dispatch<T> | The state setter, support mutation update or return immutable data |
| `controls.back` | () => void | Go back to the previous state |
| `controls.forward` | () => void | Go forward to the next state |
| `controls.reset` | () => void | Reset the state to the initial state |
| `controls.canBack` | () => boolean | Check if can go back to the previous state |
| `controls.canForward` | () => boolean | Check if can go forward to the next state |
| `controls.getHistory` | () => T[] | Get the history of the state |
| `controls.patches` | TravelPatches[] | Get the patches history of the state |
| `controls.position` | number | Get the current position of the state |
| `controls.go` | (position: number) => void | Go to the specific position of the state |
| `controls.archive` | () => void | Archive the current state(the `autoArchive` options should be `false`) |

## License

Expand Down
Loading
Loading