Skip to content

Commit

Permalink
feat(archive): implement archive API
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Mar 23, 2024
1 parent 4f64bf6 commit 9a0976b
Show file tree
Hide file tree
Showing 3 changed files with 1,026 additions and 105 deletions.
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

0 comments on commit 9a0976b

Please sign in to comment.