Skip to content

Commit 2ee6cab

Browse files
committed
Merge remote-tracking branch 'pmndrs/v5' into v5-use-sync-external-store-peer-dep
2 parents 47818ae + 3659165 commit 2ee6cab

23 files changed

+666
-1440
lines changed

.github/workflows/test-multiple-builds.yml

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,8 @@ jobs:
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
build: [cjs, umd] # [cjs, esm, umd, system]
16-
env: [development, production]
17-
devtools-skip:
18-
- CI-MATRIX-NOSKIP
19-
include:
20-
- devtools-skip: CI-MATRIX-[2345]
21-
build: umd
22-
- devtools-skip: CI-MATRIX-[1345]
23-
build: umd
24-
- devtools-skip: CI-MATRIX-[1245]
25-
build: umd
26-
- devtools-skip: CI-MATRIX-[1235]
27-
build: umd
28-
- devtools-skip: CI-MATRIX-[1234]
29-
build: umd
30-
exclude:
31-
- devtools-skip: CI-MATRIX-NOSKIP
32-
build: umd
15+
build: [cjs, esm, umd] # [cjs, esm, umd, system]
16+
env: [development] # [development, production]
3317
steps:
3418
- uses: actions/checkout@v2
3519
- uses: actions/setup-node@v2
@@ -39,10 +23,6 @@ jobs:
3923
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
4024
- run: yarn install --frozen-lockfile --check-files
4125
- run: yarn build
42-
- name: Use React 17 for production test
43-
if: ${{ matrix.env == 'production' }}
44-
run: |
45-
4626
- name: Patch for DEV-ONLY
4727
if: ${{ matrix.env == 'development' }}
4828
run: |
@@ -60,24 +40,18 @@ jobs:
6040
- name: Patch for ESM
6141
if: ${{ matrix.build == 'esm' }}
6242
run: |
63-
sed -i~ "s/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\/esm\1.js" package.json
43+
sed -i~ "s/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\/esm\1.js/" package.json
6444
sed -i~ "1s/^/import.meta.env=import.meta.env||{};import.meta.env.MODE='${NODE_ENV}';/" tests/*.tsx
6545
env:
6646
NODE_ENV: ${{ matrix.env }}
6747
- name: Patch for UMD (DEV)
6848
if: ${{ matrix.build == 'umd' && matrix.env == 'development' }}
6949
run: |
7050
sed -i~ "s/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\/umd\1.development.js/" package.json
71-
sed -i~ "s/it('\[${DEVTOOLS_SKIP}\]/it.skip('/" tests/devtools.test.tsx
72-
env:
73-
DEVTOOLS_SKIP: ${{ matrix.devtools-skip }}
7451
- name: Patch for UMD (PRD)
7552
if: ${{ matrix.build == 'umd' && matrix.env == 'production' }}
7653
run: |
7754
sed -i~ "s/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\/umd\1.production.js/" package.json
78-
sed -i~ "s/it('\[${DEVTOOLS_SKIP}\]/it.skip('/" tests/devtools.test.tsx
79-
env:
80-
DEVTOOLS_SKIP: ${{ matrix.devtools-skip }}
8155
- name: Patch for SystemJS
8256
if: ${{ matrix.build == 'system' }}
8357
run: |

.github/workflows/test-multiple-versions.yml

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,11 @@ jobs:
2828
fail-fast: false
2929
matrix:
3030
react:
31-
- 16.8.0
32-
- 17.0.0
3331
- 18.0.0
3432
- 18.1.0
3533
- 18.2.0
3634
- 18.3.0-canary-6c7b41da3-20231123
3735
- 0.0.0-experimental-6c7b41da3-20231123
38-
devtools-skip:
39-
- CI-MATRIX-NOSKIP
40-
include:
41-
- devtools-skip: CI-MATRIX-[2345]
42-
react: 16.8.0
43-
- devtools-skip: CI-MATRIX-[1345]
44-
react: 16.8.0
45-
- devtools-skip: CI-MATRIX-[1245]
46-
react: 16.8.0
47-
- devtools-skip: CI-MATRIX-[1235]
48-
react: 16.8.0
49-
- devtools-skip: CI-MATRIX-[1234]
50-
react: 16.8.0
51-
exclude:
52-
- devtools-skip: CI-MATRIX-NOSKIP
53-
react: 16.8.0
5436
steps:
5537
- uses: actions/checkout@v2
5638
- uses: actions/setup-node@v2
@@ -59,19 +41,7 @@ jobs:
5941
cache: yarn
6042
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
6143
- run: yarn install --frozen-lockfile --check-files
62-
- name: Install legacy testing-library
63-
if: ${{ startsWith(matrix.react, '16.') || startsWith(matrix.react, '17.') }}
64-
run: yarn add -D @testing-library/[email protected]
65-
- name: Patch for React 16
66-
if: ${{ startsWith(matrix.react, '16.') }}
67-
run: |
68-
sed -i~ '1s/^/import React from "react";/' tests/*.tsx
69-
sed -i~ 's/"jsx": "react-jsx"/"jsx": "react"/' tsconfig.json
70-
sed -i~ 's/import\.meta\.env[?]\.MODE/"DEVELOPMENT".toLowerCase()/' src/*.ts src/*/*.ts
71-
sed -i~ "s/it('\[${DEVTOOLS_SKIP}\]/it.skip('/" tests/devtools.test.tsx
72-
env:
73-
DEVTOOLS_SKIP: ${{ matrix.devtools-skip }}
74-
- name: Test ${{ matrix.react }} ${{ matrix.devtools-skip }}
44+
- name: Test ${{ matrix.react }}
7545
run: |
7646
yarn add -D react@${{ matrix.react }} react-dom@${{ matrix.react }}
7747
yarn test:ci

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ you can use this suggested workflow:
7070
- Create failing tests for your fix or new feature;
7171
- Implement your changes and confirm that all test are passing.
7272
You can run the tests continuously during development
73-
with the `yarn test:dev` command.
73+
with the `yarn test` command.
7474
- If you want to test it in a React project:
7575
- Either use `yarn link`, or
7676
- Use the `yalc` package.

docs/guides/typescript.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,9 @@ const bearStore = createStore<BearState>()((set) => ({
443443
}))
444444

445445
function useBearStore(): BearState
446-
function useBearStore<T>(
447-
selector: (state: BearState) => T,
448-
equals?: (a: T, b: T) => boolean,
449-
): T
450-
function useBearStore<T>(
451-
selector?: (state: BearState) => T,
452-
equals?: (a: T, b: T) => boolean,
453-
) {
454-
return useStore(bearStore, selector!, equals)
446+
function useBearStore<T>(selector: (state: BearState) => T): T
447+
function useBearStore<T>(selector?: (state: BearState) => T) {
448+
return useStore(bearStore, selector!)
455449
}
456450
```
457451
@@ -471,15 +465,13 @@ const bearStore = createStore<BearState>()((set) => ({
471465
increase: (by) => set((state) => ({ bears: state.bears + by })),
472466
}))
473467

474-
const createBoundedUseStore = ((store) => (selector, equals) =>
475-
useStore(store, selector as never, equals)) as <S extends StoreApi<unknown>>(
468+
const createBoundedUseStore = ((store) => (selector) => useStore(store)) as <
469+
S extends StoreApi<unknown>,
470+
>(
476471
store: S,
477472
) => {
478473
(): ExtractState<S>
479-
<T>(
480-
selector: (state: ExtractState<S>) => T,
481-
equals?: (a: T, b: T) => boolean,
482-
): T
474+
<T>(selector: (state: ExtractState<S>) => T): T
483475
}
484476

485477
type ExtractState<S> = S extends { getState: () => infer X } ? X : never

docs/integrations/immer-middleware.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,5 @@ Zustand will skip calling the subscriptions.
125125

126126
## CodeSandbox Demo
127127

128-
- [Basic](https://codesandbox.io/s/zustand-updating-draft-states-basic-demo-zkp22g),
129-
- [Advanced](https://codesandbox.io/s/zustand-updating-draft-states-advanced-demo-3znqzk).
128+
- [Basic](https://codesandbox.io/p/sandbox/zustand-updating-draft-states-basic-demo-forked-96mkdw),
129+
- [Advanced](https://codesandbox.io/p/sandbox/zustand-updating-draft-states-advanced-demo-forked-phkzzg).

docs/integrations/persisting-store-data.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ export const useBoundStore = create(
630630
)
631631
```
632632

633-
If you're using a type that JSON.stringify() doesn't support, you'll need to write your own serialization/deserialization code. However, if this is tedious, you can use third-party libraries to serialize and deserialize different types of data.
633+
If you're using a type that `JSON.stringify()` doesn't support, you'll need to write your own serialization/deserialization code. However, if this is tedious, you can use third-party libraries to serialize and deserialize different types of data.
634634

635635
For example, [Superjson](https://github.com/blitz-js/superjson) can serialize data along with its type, allowing the data to be parsed back to its original type upon deserialization
636636

@@ -735,15 +735,10 @@ export const useBearStore = create<MyState>()(
735735

736736
### How do I use it with Map and Set
737737

738-
With the previous persist API, you would use `serialize`/`deserialize`
739-
to deal with `Map` and `Set` and convert them into
740-
an Array so they could be parsed into proper JSON.
738+
In order to persist object types such as `Map` and `Set`, they will need to be converted to JSON-serializable types such as an `Array` which can be done by defining a custom `storage` engine.
741739

742-
The new persist API has deprecated `serialize`/`deserialize`.
743-
744-
Now, you will need to use the `storage` prop.
745740
Let's say your state uses `Map` to handle a list of `transactions`,
746-
then you can convert the Map into an Array in the storage prop:
741+
then you can convert the `Map` into an `Array` in the `storage` prop which is shown below:
747742

748743
```ts
749744

package.json

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,6 @@
134134
"types": "./traditional.d.ts",
135135
"default": "./traditional.js"
136136
}
137-
},
138-
"./context": {
139-
"import": {
140-
"types": "./esm/context.d.mts",
141-
"default": "./esm/context.mjs"
142-
},
143-
"module": {
144-
"types": "./esm/context.d.ts",
145-
"default": "./esm/context.js"
146-
},
147-
"default": {
148-
"types": "./context.d.ts",
149-
"default": "./context.js"
150-
}
151137
}
152138
},
153139
"sideEffects": false,
@@ -162,7 +148,6 @@
162148
"build:vanilla:shallow": "rollup -c --config-vanilla_shallow",
163149
"build:react:shallow": "rollup -c --config-react_shallow",
164150
"build:traditional": "rollup -c --config-traditional",
165-
"build:context": "rollup -c --config-context",
166151
"postbuild": "yarn patch-d-ts && yarn copy && yarn patch-esm-ts",
167152
"prettier": "prettier \"*.{js,json,md}\" \"{examples,src,tests,docs}/**/*.{js,jsx,ts,tsx,md,mdx}\" --write",
168153
"prettier:ci": "prettier '*.{js,json,md}' '{examples,src,tests,docs}/**/*.{js,jsx,ts,tsx,md,mdx}' --list-different",
@@ -264,6 +249,9 @@
264249
"immer": {
265250
"optional": true
266251
},
252+
"immer": {
253+
"optional": true
254+
},
267255
"react": {
268256
"optional": true
269257
},

rollup.config.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,13 @@ function createESMConfig(input, output) {
7878
}
7979
}
8080

81-
function createCommonJSConfig(input, output, options) {
81+
function createCommonJSConfig(input, output) {
8282
return {
8383
input,
8484
output: {
8585
file: `${output}.js`,
8686
format: 'cjs',
8787
esModule: false,
88-
outro: options.addModuleExport
89-
? [
90-
`module.exports = ${options.addModuleExport.default};`,
91-
...Object.entries(options.addModuleExport)
92-
.filter(([key]) => key !== 'default')
93-
.map(([key, value]) => `module.exports.${key} = ${value};`),
94-
`exports.default = module.exports;`,
95-
].join('\n')
96-
: '',
9788
},
9889
external,
9990
plugins: [
@@ -176,18 +167,7 @@ module.exports = function (args) {
176167
}
177168
return [
178169
...(c === 'index' ? [createDeclarationConfig(`src/${c}.ts`, 'dist')] : []),
179-
createCommonJSConfig(`src/${c}.ts`, `dist/${c}`, {
180-
addModuleExport: {
181-
index: {
182-
default: 'react',
183-
create: 'create',
184-
useStore: 'useStore',
185-
createStore: 'vanilla.createStore',
186-
},
187-
vanilla: { default: 'vanilla', createStore: 'createStore' },
188-
shallow: { default: 'shallow', shallow: 'shallow$1' },
189-
}[c],
190-
}),
170+
createCommonJSConfig(`src/${c}.ts`, `dist/${c}`),
191171
createESMConfig(`src/${c}.ts`, `dist/esm/${c}.js`),
192172
createESMConfig(`src/${c}.ts`, `dist/esm/${c}.mjs`),
193173
createUMDConfig(`src/${c}.ts`, `dist/umd/${c}`, 'development'),

src/context.ts

Lines changed: 0 additions & 102 deletions
This file was deleted.

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
export * from './vanilla.ts'
22
export * from './react.ts'
3-
export { default } from './react.ts'

0 commit comments

Comments
 (0)