Skip to content

Commit 2491918

Browse files
committed
fix(type): fix type and update doc
1 parent 44a9e85 commit 2491918

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,16 @@ const App = () => {
8989

9090
### Parameters
9191

92-
| Parameter | type | description | default |
93-
| ------------------ | ------------- | ------------------------------------------------------------------------------------------------------------------------ | -------------------------------- |
94-
| `maxHistory` | number | The maximum number of history to keep | 10 |
95-
| `initialPatches` | TravelPatches | The initial patches | {patches: [],inversePatches: []} |
96-
| `initialPosition` | number | The initial position of the state | 0 |
97-
| `autoArchive` | boolean | Auto archive the state (see [Archive Mode](#archive-mode) for details) | true |
98-
| `enableAutoFreeze` | boolean | Enable auto freeze the state, [view more](https://github.com/unadlib/mutative?tab=readme-ov-file#createstate-fn-options) | false |
99-
| `strict` | boolean | Enable strict mode, [view more](https://github.com/unadlib/mutative?tab=readme-ov-file#createstate-fn-options) | false |
100-
| `mark` | Mark<O, F>[] | The mark function , [view more](https://github.com/unadlib/mutative?tab=readme-ov-file#createstate-fn-options) | () => void |
92+
| Parameter | type | description | default |
93+
| ------------------ | --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------- |
94+
| `maxHistory` | `number` | The maximum number of history to keep | 10 |
95+
| `initialPatches` | `TravelPatches` | The initial patches | {patches: [],inversePatches: []} |
96+
| `initialPosition` | `number` | The initial position of the state | 0 |
97+
| `autoArchive` | `boolean` | Auto archive the state (see [Archive Mode](#archive-mode) for details) | true |
98+
| `enableAutoFreeze` | `boolean` | Enable auto freeze the state, [view more](https://github.com/unadlib/mutative?tab=readme-ov-file#createstate-fn-options) | false |
99+
| `strict` | `boolean` | Enable strict mode, [view more](https://github.com/unadlib/mutative?tab=readme-ov-file#createstate-fn-options) | false |
100+
| `mark` | `Mark<O, F>[]` | The mark function , [view more](https://github.com/unadlib/mutative?tab=readme-ov-file#createstate-fn-options) | () => void |
101+
| `patchesOptions` | `boolean | PatchesOptions` | Customize JSON Patch format. Supports `{ pathAsArray: boolean }` to control path format. See [Mutative patches docs](https://mutative.js.org/docs/api-reference/create#patches) | `true` (enable patches) |
101102

102103
### Returns
103104

@@ -187,9 +188,12 @@ In manual archive mode, you control when state changes are recorded to history u
187188
**Use Case 1: Batch multiple changes into one history entry**
188189

189190
```jsx
190-
const [state, setState, controls] = useTravel({ count: 0 }, {
191-
autoArchive: false
192-
});
191+
const [state, setState, controls] = useTravel(
192+
{ count: 0 },
193+
{
194+
autoArchive: false,
195+
}
196+
);
193197

194198
// Multiple setState calls across different renders
195199
setState({ count: 1 }); // Temporary change (not in history yet)
@@ -217,6 +221,7 @@ function handleSave() {
217221
```
218222

219223
The key difference:
224+
220225
- **Auto archive**: Each `setState` = one undo step
221226
- **Manual archive**: `archive()` call = one undo step (can include multiple `setState` calls)
222227

src/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function useTravel<
5151
P extends PatchesOption = {},
5252
>(
5353
initialState: S,
54-
options: Omit<TravelsOptions<F, true, P>, 'autoArchive'> & {
54+
options: Omit<TravelsOptions<F, true, P>, 'autoArchive' | 'mutable'> & {
5555
autoArchive?: true;
5656
}
5757
): [Value<S, F>, (updater: Updater<S>) => void, TravelsControls<S, F, P>];
@@ -62,7 +62,7 @@ export function useTravel<
6262
P extends PatchesOption = {},
6363
>(
6464
initialState: S,
65-
options: Omit<TravelsOptions<F, false, P>, 'autoArchive'> & {
65+
options: Omit<TravelsOptions<F, false, P>, 'autoArchive' | 'mutable'> & {
6666
autoArchive: false;
6767
}
6868
): [Value<S, F>, (updater: Updater<S>) => void, ManualTravelsControls<S, F, P>];
@@ -108,7 +108,10 @@ export function useTravel<
108108
// Create Travels instance (only once)
109109
const travelsRef = useRef<Travels<S, F, A>>();
110110
if (!travelsRef.current) {
111-
travelsRef.current = new Travels<S, F, A>(initialState, _options);
111+
travelsRef.current = new Travels<S, F, A>(initialState, {
112+
..._options,
113+
mutable: false,
114+
});
112115
}
113116

114117
// Force re-render when state changes

0 commit comments

Comments
 (0)