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

switch to isTracking flag #115

Merged
merged 3 commits into from
Jun 15, 2023
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ interface TemporalState<TState> {
redo: (steps?: number) => void;
clear: () => void;

trackingStatus: 'paused' | 'tracking';
isTracking: boolean;
pause: () => void;
resume: () => void;

Expand Down Expand Up @@ -361,21 +361,21 @@ interface TemporalState<TState> {

#### **Stop and start history**

`trackingStatus: 'paused' | 'tracking'`
`isTracking: boolean`

`trackingStatus`: a stateful string in the `temporal` store that indicates whether the `temporal` store is tracking state changes or not. Possible values are `'paused'` or `'tracking'`. To programmatically pause and resume tracking, use `pause()` and `resume()` explained below.
`isTracking`: a stateful flag in the `temporal` store that indicates whether the `temporal` store is tracking state changes or not. Possible values are `true` or `false`. To programmatically pause and resume tracking, use `pause()` and `resume()` explained below.

#### **Pause tracking of history**

`pause: () => void`

`pause`: call function to pause tracking state changes. This will prevent new states from being stored in history within the temporal store.
`pause`: call function to pause tracking state changes. This will prevent new states from being stored in history within the temporal store. Sets `isTracking` to `false`.

#### **Resume tracking of history**

`resume: () => void`

`resume`: call function to resume tracking state changes. This will allow new states to be stored in history within the temporal store.
`resume`: call function to resume tracking state changes. This will allow new states to be stored in history within the temporal store. Sets `isTracking` to `true`.

#### **Programmatically add middleware to the setter**

Expand Down Expand Up @@ -407,7 +407,7 @@ This is a work in progress. Submit a PR!

## Contributing

PRs are welcome! [pnpm](https://pnpm.io/) is used as a package manager. Run `pnpm install` to install local dependencies. Library code is located at `packages/zundo`.
PRs are welcome! [pnpm](https://pnpm.io/) is used as a package manager. Run `pnpm install` to install local dependencies.

## Author

Expand Down
12 changes: 6 additions & 6 deletions __tests__/zundo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('temporal middleware', () => {
clear,
pastStates,
futureStates,
trackingStatus,
isTracking,
pause,
resume,
setOnSave,
Expand All @@ -58,7 +58,7 @@ describe('temporal middleware', () => {
expect(clear).toBeDefined();
expect(pastStates).toBeDefined();
expect(futureStates).toBeDefined();
expect(trackingStatus).toBeDefined();
expect(isTracking).toBeDefined();
expect(pause).toBeDefined();
expect(resume).toBeDefined();
expect(setOnSave).toBeDefined();
Expand Down Expand Up @@ -319,16 +319,16 @@ describe('temporal middleware', () => {

describe('temporal tracking status', () => {
it('should initialize state to tracking', () => {
const { trackingStatus } = store.temporal.getState();
expect(trackingStatus).toBe('tracking');
const { isTracking } = store.temporal.getState();
expect(isTracking).toBe(true);
});

it('should switch to paused', () => {
const { pause } = store.temporal.getState();
act(() => {
pause();
});
expect(store.temporal.getState().trackingStatus).toBe('paused');
expect(store.temporal.getState().isTracking).toBe(false);
});

it('should switch to tracking', () => {
Expand All @@ -337,7 +337,7 @@ describe('temporal middleware', () => {
pause();
resume();
});
expect(store.temporal.getState().trackingStatus).toBe('tracking');
expect(store.temporal.getState().isTracking).toBe(true);
});

it('does not track state when paused', () => {
Expand Down
10 changes: 5 additions & 5 deletions examples/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"just-throttle": "4.2.0",
"lodash.merge": "4.6.2",
"lodash.throttle": "4.1.1",
"next": "13.4.4",
"next": "13.4.6",
"react": "18.2.0",
"react-dom": "18.2.0",
"zundo": "workspace:*",
Expand All @@ -21,9 +21,9 @@
"devDependencies": {
"@types/lodash.merge": "4.6.7",
"@types/lodash.throttle": "4.1.7",
"@types/node": "20.2.5",
"@types/react": "18.2.7",
"eslint": "8.41.0",
"typescript": "5.0.4"
"@types/node": "20.3.1",
"@types/react": "18.2.12",
"eslint": "8.42.0",
"typescript": "5.1.3"
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@testing-library/jest-dom": "5.16.5",
"@testing-library/react": "14.0.0",
"@types/lodash.throttle": "4.1.7",
"@types/react-dom": "18.2.4",
"@types/react-dom": "18.2.5",
"jsdom": "22.1.0",
"lodash.throttle": "4.1.1",
"prettier": "2.8.8",
Expand All @@ -56,9 +56,9 @@
"react-test-renderer": "18.2.0",
"size-limit": "8.2.4",
"tsup": "6.7.0",
"typescript": "5.0.4",
"typescript": "5.1.3",
"vite": "4.3.9",
"vitest": "0.31.1",
"vitest": "0.32.0",
"vitest-localstorage-mock": "0.0.1",
"zustand": "4.3.8"
},
Expand Down
Loading