Skip to content

Commit

Permalink
cleanup for next release (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
charkour authored Jan 11, 2023
1 parent 0eb3205 commit a4195e3
Show file tree
Hide file tree
Showing 15 changed files with 1,165 additions and 1,250 deletions.
12 changes: 6 additions & 6 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
"lint": "next lint"
},
"dependencies": {
"next": "12.2.5",
"next": "13.1.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"ui": "workspace:*"
},
"devDependencies": {
"@types/node": "18.11.18",
"@types/react": "18.0.26",
"eslint": "8.31.0",
"eslint-config-custom": "workspace:*",
"eslint": "8.22.0",
"next-transpile-modules": "9.0.0",
"next-transpile-modules": "10.0.0",
"tsconfig": "workspace:*",
"@types/node": "16.11.7",
"@types/react": "18.0.17",
"typescript": "4.7.4"
"typescript": "4.9.4"
}
}
12 changes: 6 additions & 6 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
"dependencies": {
"@types/lodash.throttle": "4.1.7",
"lodash.throttle": "4.1.1",
"next": "12.2.5",
"next": "13.1.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"ui": "workspace:*",
"zundo": "workspace:*",
"zustand": "4.3.1"
},
"devDependencies": {
"@types/node": "16.11.7",
"@types/react": "18.0.17",
"eslint": "8.22.0",
"@types/node": "18.11.18",
"@types/react": "18.0.26",
"eslint": "8.31.0",
"eslint-config-custom": "workspace:*",
"next-transpile-modules": "9.0.0",
"next-transpile-modules": "10.0.0",
"tsconfig": "workspace:*",
"typescript": "4.7.4"
"typescript": "4.9.4"
}
}
5 changes: 2 additions & 3 deletions apps/web/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import throttle from 'lodash.throttle';
import { Button } from 'ui';
import { temporal } from 'zundo';
import { create } from 'zustand';
import { createStore as createVanilla } from 'zustand/vanilla';
import { create, createStore } from 'zustand';
import { shallow } from 'zustand/shallow';

interface MyState {
Expand All @@ -26,7 +25,7 @@ const withZundo = temporal<MyState>(
},
);

const originalStore = createVanilla(withZundo);
const originalStore = createStore(withZundo);

const useStore = create(originalStore);
const useTemporalStore = create(originalStore.temporal);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
},
"devDependencies": {
"eslint-config-custom": "workspace:*",
"prettier": "2.7.1",
"turbo": "1.4.3"
"prettier": "2.8.2",
"turbo": "1.7.0"
},
"engines": {
"npm": ">=7.0.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/eslint-config-custom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"eslint": "8.22.0",
"eslint-config-next": "12.2.5",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-react": "7.30.1",
"typescript": "4.7.4"
"eslint": "8.31.0",
"eslint-config-next": "13.1.1",
"eslint-config-prettier": "8.6.0",
"eslint-plugin-react": "7.31.11",
"typescript": "4.9.4"
},
"publishConfig": {
"access": "public"
Expand Down
10 changes: 5 additions & 5 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"lint": "eslint *.ts*"
},
"devDependencies": {
"@types/react": "latest",
"@types/react-dom": "latest",
"eslint": "latest",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.10",
"eslint": "^8.31.0",
"eslint-config-custom": "workspace:*",
"react": "latest",
"react": "^18.2.0",
"tsconfig": "workspace:*",
"typescript": "latest"
"typescript": "^4.9.4"
}
}
6 changes: 4 additions & 2 deletions packages/zundo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Try a live [demo](https://codesandbox.io/s/currying-flower-2dom9?file=/src/App.t
npm i zustand zundo@beta
```

> zustand v4.1.0 or higher is required for TS usage. v4.0.0 or higher is required for JS usage.
> zustand v4.3.0 or higher is required for TS usage. v4.0.0 or higher is required for JS usage.
## Background

Expand All @@ -36,7 +36,7 @@ This returns the familiar store accessible by a hook! But now your store tracks

```tsx
import { temporal } from 'zundo'
import create from 'zustand'
import { create } from 'zustand'

// define the store (typescript)
interface StoreState {
Expand Down Expand Up @@ -342,6 +342,8 @@ interface TemporalState<TState> {
<details>
<summary>Click to expand</summary>

This is a work in progress. Submit a PR!

</details>

## Road Map
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions packages/zundo/__tests__/createVanillaTemporal.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect, vi } from 'vitest';
vi.mock('zustand/vanilla');
vi.mock('zustand');
import { createVanillaTemporal } from '../src/temporal';
import { createStore as createVanilla } from 'zustand/vanilla';
import { createStore } from 'zustand';
import { act } from 'react-dom/test-utils';

interface MyState {
Expand All @@ -13,7 +13,7 @@ interface MyState {
// tests the createVanillaTemporal function rather than the temporal middleware
// Not exhaustive, but also likely not needed
describe('createVanillaTemporal', () => {
const store = createVanilla<MyState>((set) => {
const store = createStore<MyState>((set) => {
return {
count: 0,
increment: () =>
Expand Down
32 changes: 16 additions & 16 deletions packages/zundo/__tests__/options.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
vi.mock('zustand/vanilla');
vi.mock('zustand');
import { temporal } from '../src/index';
import { createStore as createVanilla, StoreApi } from 'zustand/vanilla';
import { createStore, type StoreApi } from 'zustand';
import { act } from 'react-dom/test-utils';
import { shallow } from 'zustand/shallow';
import type {
Expand All @@ -20,10 +20,10 @@ interface MyState {
doNothing: () => void;
}

const createStore = (
const createVanillaStore = (
options?: ZundoOptions<MyState, Pick<MyState, 'count'>>,
) => {
return createVanilla<MyState>()(
return createStore<MyState>()(
temporal((set) => {
return {
count: 0,
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('Middleware options', () => {
>;
// Recreate store for each test
beforeEach(() => {
store = createStore();
store = createVanillaStore();
});

describe('partialize', () => {
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('Middleware options', () => {
});

it('should partialize the past states', () => {
const storeWithPartialize = createStore({
const storeWithPartialize = createVanillaStore({
partialize: (state) => ({
count: state.count,
}),
Expand All @@ -114,7 +114,7 @@ describe('Middleware options', () => {
});

it('should partialize the future states', () => {
const storeWithPartialize = createStore({
const storeWithPartialize = createVanillaStore({
partialize: (state) => ({
count: state.count,
}),
Expand Down Expand Up @@ -183,7 +183,7 @@ describe('Middleware options', () => {
});

it('should limit the number of past states when set', () => {
const storeWithLimit = createStore({ limit: 3 });
const storeWithLimit = createVanillaStore({ limit: 3 });
const { increment } = storeWithLimit.getState();
act(() => {
increment();
Expand All @@ -204,7 +204,7 @@ describe('Middleware options', () => {

describe('equality function', () => {
it('should use the equality function when set', () => {
const storeWithEquality = createStore({
const storeWithEquality = createVanillaStore({
equality: (currentState, pastState) =>
currentState.count === pastState.count,
});
Expand All @@ -227,7 +227,7 @@ describe('Middleware options', () => {
});

it('should use an external equality function', () => {
const storeWithEquality = createStore({
const storeWithEquality = createVanillaStore({
equality: shallow,
});
const { doNothing, increment } = storeWithEquality.getState();
Expand Down Expand Up @@ -271,7 +271,7 @@ describe('Middleware options', () => {
describe('onSave', () => {
it('should call the onSave function when set through options', () => {
global.console.info = vi.fn();
const storeWithOnSave = createStore({
const storeWithOnSave = createVanillaStore({
onSave: (pastStates) => {
console.info(pastStates);
},
Expand Down Expand Up @@ -312,7 +312,7 @@ describe('Middleware options', () => {
global.console.info = vi.fn();
global.console.log = vi.fn();
global.console.error = vi.fn();
const storeWithOnSave = createStore({
const storeWithOnSave = createVanillaStore({
onSave: (pastStates) => {
console.info(pastStates);
},
Expand Down Expand Up @@ -368,7 +368,7 @@ describe('Middleware options', () => {

it('should call function if set', () => {
global.console.info = vi.fn();
const storeWithHandleSet = createStore({
const storeWithHandleSet = createVanillaStore({
handleSet: (handleSet) => {
return (state) => {
console.info('handleSet called');
Expand Down Expand Up @@ -396,7 +396,7 @@ describe('Middleware options', () => {
it('should correctly use throttling', () => {
global.console.error = vi.fn();
vi.useFakeTimers();
const storeWithHandleSet = createStore({
const storeWithHandleSet = createVanillaStore({
handleSet: (handleSet) => {
return throttle<typeof handleSet>((state) => {
console.error('handleSet called');
Expand Down Expand Up @@ -457,7 +457,7 @@ describe('Middleware options', () => {
});
it('should call onSave cb without adding a new state when onSave is set at store init options', () => {
global.console.info = vi.fn();
const storeWithOnSave = createStore({
const storeWithOnSave = createVanillaStore({
onSave: (pastStates) => {
console.info(pastStates);
},
Expand All @@ -474,7 +474,7 @@ describe('Middleware options', () => {
it('should call onSave cb without adding a new state and respond to new setOnSave', () => {
global.console.dir = vi.fn();
global.console.trace = vi.fn();
const storeWithOnSave = createStore({
const storeWithOnSave = createVanillaStore({
onSave: (pastStates) => {
console.dir(pastStates);
},
Expand Down
6 changes: 3 additions & 3 deletions packages/zundo/__tests__/zundo.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
vi.mock('zustand/vanilla');
vi.mock('zustand');
import { temporal } from '../src/index';
import { createStore as createVanilla, type StoreApi } from 'zustand/vanilla';
import { createStore, type StoreApi } from 'zustand';
import { act } from 'react-dom/test-utils';
import type { TemporalState, Write } from '../src/types';

Expand All @@ -21,7 +21,7 @@ describe('temporal middleware', () => {
>;
// Recreate store for each test
beforeEach(() => {
store = createVanilla<MyState>()(
store = createStore<MyState>()(
temporal((set) => {
return {
count: 0,
Expand Down
8 changes: 4 additions & 4 deletions packages/zundo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
"devDependencies": {
"@size-limit/preset-small-lib": "8.1.0",
"@types/lodash.throttle": "4.1.7",
"@types/react-dom": "18.0.6",
"@types/react-dom": "18.0.10",
"lodash.throttle": "4.1.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"size-limit": "8.1.0",
"tsconfig": "workspace:*",
"tsup": "6.2.3",
"typescript": "4.8.3",
"vitest": "0.23.4",
"tsup": "6.5.0",
"typescript": "4.9.4",
"vitest": "0.27.0",
"zustand": "4.3.1"
},
"peerDependencies": {
Expand Down
15 changes: 5 additions & 10 deletions packages/zundo/src/temporal.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createStore as createVanilla, type StoreApi } from 'zustand/vanilla';
import { createStore, type StoreApi } from 'zustand';
import type { TemporalStateWithInternals, ZundoOptions } from './types';

export const createVanillaTemporal = <TState>(
Expand All @@ -14,7 +14,7 @@ export const createVanillaTemporal = <TState>(
};
const { partialize, onSave, limit, equality } = options;

return createVanilla<TemporalStateWithInternals<TState>>()((set, get) => {
return createStore<TemporalStateWithInternals<TState>>()((set, get) => {
const pastStates: TState[] = [];
const futureStates: TState[] = [];

Expand All @@ -28,9 +28,7 @@ export const createVanillaTemporal = <TState>(
return;
}

const skippedPastStates = ps.splice(
ps.length - (steps - 1),
);
const skippedPastStates = ps.splice(ps.length - (steps - 1));
const pastState = ps.pop();
if (pastState) {
fs.push(partialize(userGet()));
Expand All @@ -47,9 +45,7 @@ export const createVanillaTemporal = <TState>(
return;
}

const skippedFutureStates = fs.splice(
fs.length - (steps - 1),
);
const skippedFutureStates = fs.splice(fs.length - (steps - 1));
const futureState = fs.pop();
if (futureState) {
ps.push(partialize(userGet()));
Expand All @@ -75,8 +71,7 @@ export const createVanillaTemporal = <TState>(
__internal: {
onSave,
handleUserSet: (pastState) => {
const { trackingStatus, pastStates, __internal } =
get();
const { trackingStatus, pastStates, __internal } = get();
const ps = pastStates.slice();
const currentState = partialize(userGet());
if (
Expand Down
8 changes: 1 addition & 7 deletions packages/zundo/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StoreApi } from 'zustand/vanilla';
import type { StoreApi } from 'zustand';

type onSave<TState> = (pastState: TState, currentState: TState) => void;

Expand Down Expand Up @@ -31,12 +31,6 @@ export interface ZundoOptions<TState, PartialTState = TState> {
) => StoreApi<TState>['setState'];
}

export type PopArgument<T extends (...a: never[]) => unknown> = T extends (
...a: [...infer A, infer _]
) => infer R
? (...a: A) => R
: never;

export type Write<T, U> = Omit<T, keyof U> & U;

export type TemporalState<TState> = Omit<
Expand Down
Loading

0 comments on commit a4195e3

Please sign in to comment.