Skip to content

Commit d1caed8

Browse files
authored
Merge pull request #8 from mayank1513/touchup.js
Touchup.js
2 parents 3aabcdf + 8c928fe commit d1caed8

File tree

11 files changed

+80
-38
lines changed

11 files changed

+80
-38
lines changed

.vscode/extensions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"recommendations": ["esbenp.prettier-vscode"]
2+
"recommendations": ["esbenp.prettier-vscode", "mayank1513.trello-kanban-task-board"]
33
}

README.md

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
1-
# PersistAndSync Zustand Store
1+
# Persist-And-Sync Zustand Store
22

33
[![test](https://github.com/react18-tools/persist-and-sync/actions/workflows/test.yml/badge.svg)](https://github.com/react18-tools/persist-and-sync/actions/workflows/test.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/5355eb02cfedc9184e3f/maintainability)](https://codeclimate.com/github/mayank1513/persist-and-sync/maintainability) [![codecov](https://codecov.io/gh/mayank1513/persist-and-sync/graph/badge.svg)](https://codecov.io/gh/mayank1513/persist-and-sync) [![Version](https://img.shields.io/npm/v/persist-and-sync.svg?colorB=green)](https://www.npmjs.com/package/persist-and-sync) [![Downloads](https://img.jsdelivr.com/img.shields.io/npm/dt/persist-and-sync.svg)](https://www.npmjs.com/package/persist-and-sync) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/persist-and-sync)
44

5-
> Zustand middleware to easily persist and sync Zustand state between tabs / windows / iframes (Same Origin)
5+
> Zustand middleware to easily persist and sync Zustand state between tabs/windows/iframes (Same Origin)
66
7-
> Motivation: Recently I got caught up in several issues working with persist middleware and syncing tabs with Zustand. This is a simple light weight middleware to persist and instantly share state between tabs or windows
7+
> Motivation: Recently I got caught up in several issues working with the persist middleware and syncing tabs with Zustand. This is a simple lightweight middleware to persist and instantly share state between tabs or windows
88
9-
- ✅ 🐙 (642 Bytes gZiped) ~ 0.5 kB size cross-tab state sharing + persistence for zustand
9+
- ✅ 🐙 ~ 1 kB size cross-tab state sharing + persistence for zustand
1010
- ✅ Full TypeScript Support
11-
- ✅ solid reliability in 1 writing and n reading tab-scenarios (with changing writing tab)
12-
- ✅ Fire and forget approach of always using the latest state. Perfect for single user systems
11+
- ✅ solid reliability in 1 writing and n reading tab scenarios (with changing writing tab)
12+
- ✅ Fire and forget approach of always using the latest state. Perfect for single-user systems
1313
- ✅ Share state between multiple browsing contexts
14-
- ✅ Additional control over which fields to persist-and-sync and which to ignore
14+
- ✅ Additional control over which fields to `persist-and-sync` and which to ignore
1515
- ✅ Optimized for performance using memoization and closures.
1616

1717
## Install
1818

1919
```bash
2020
$ pnpm add persist-and-sync
21-
# or
21+
```
22+
23+
**or**
24+
25+
```bash
2226
$ npm install persist-and-sync
23-
# or
27+
```
28+
29+
**or**
30+
31+
```bash
2432
$ yarn add persist-and-sync
2533
```
2634

2735
## Usage
2836

29-
Simply add the middleware while creating the store and the rest will be taken care.
37+
Add the middleware while creating the store and the rest will be taken care.
3038

3139
```ts
3240
import { create } from "zustand";
@@ -43,7 +51,7 @@ const useStore = create<MyStore>(
4351
count: 0,
4452
set: n => set({ count: n }),
4553
}),
46-
{ name: "my-channel" },
54+
{ name: "my-example" },
4755
),
4856
);
4957
```
@@ -114,15 +122,15 @@ For more details about regExp check out - [JS RegExp](https://www.w3schools.com/
114122

115123
### Exact match
116124

117-
For exactly matching a parameter/field use `/^your-field-name$/`. `^` forces match from the first caracter and similarly, `$` forces match until last character.
125+
For exactly matching a parameter/field use `/^your-field-name$/`. `^` forces match from the first caracter and similarly, `$` forces match until the last character.
118126

119127
### Ignore multiple fields with exact match
120128

121129
use `regExpToIgnore: /^(field1|field2|field3)$/`
122130

123-
### 🤩 Don't forger to start [this repo](https://github.com/mayank1513/persist-and-sync)!
131+
### 🤩 Don't forget to star [this repo](https://github.com/mayank1513/persist-and-sync)!
124132

125-
Want hands-on course for getting started with Turborepo? Check out [React and Next.js with TypeScript](https://mayank-chaudhari.vercel.app/courses/react-and-next-js-with-typescript) and [The Game of Chess with Next.js, React and TypeScrypt](https://www.udemy.com/course/game-of-chess-with-nextjs-react-and-typescrypt/?referralCode=851A28F10B254A8523FE)
133+
Want a hands-on course for getting started with Turborepo? Check out [React and Next.js with TypeScript](https://mayank-chaudhari.vercel.app/courses/react-and-next-js-with-typescript) and [The Game of Chess with Next.js, React and TypeScrypt](https://www.udemy.com/course/game-of-chess-with-nextjs-react-and-typescrypt/?referralCode=851A28F10B254A8523FE)
126134

127135
## License
128136

examples/nextjs/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# nextjs-example
22

3+
## 1.0.4
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
9+
310
## 1.0.3
411

512
### Patch Changes

examples/nextjs/package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nextjs-example",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"private": true,
55
"scripts": {
66
"dev": "next dev --port 3001",
@@ -9,19 +9,19 @@
99
"lint": "next lint"
1010
},
1111
"dependencies": {
12-
"next": "^14.0.3",
12+
"next": "^14.0.4",
1313
"persist-and-sync": "workspace:*",
1414
"react": "^18.2.0",
1515
"react-dom": "^18.2.0",
1616
"zustand": "^4.4.7"
1717
},
1818
"devDependencies": {
19-
"@next/eslint-plugin-next": "^14.0.3",
20-
"@types/node": "^20.10.2",
21-
"@types/react": "^18.2.41",
22-
"@types/react-dom": "^18.2.17",
19+
"@next/eslint-plugin-next": "^14.0.4",
20+
"@types/node": "^20.10.5",
21+
"@types/react": "^18.2.46",
22+
"@types/react-dom": "^18.2.18",
2323
"eslint-config-custom": "workspace:*",
2424
"tsconfig": "workspace:*",
25-
"typescript": "^5.3.2"
25+
"typescript": "^5.3.3"
2626
}
2727
}

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
},
1010
"devDependencies": {
1111
"@changesets/cli": "^2.27.1",
12-
"eslint": "^8.55.0",
13-
"prettier": "^3.1.0",
12+
"eslint": "^8.56.0",
13+
"prettier": "^3.1.1",
1414
"tsconfig": "workspace:*",
15-
"turbo": "^1.10.16"
15+
"turbo": "^1.11.2"
1616
},
1717
"packageManager": "[email protected]",
1818
"name": "turbo-template"

packages/eslint-config-custom/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"private": true,
66
"devDependencies": {
77
"@vercel/style-guide": "^5.1.0",
8-
"eslint-config-turbo": "^1.10.16"
8+
"eslint-config-turbo": "^1.11.2"
99
}
1010
}

packages/persist-and-sync/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# persist-and-sync
22

3+
## 1.1.2
4+
5+
### Patch Changes
6+
7+
- Update dependencies
8+
39
## 1.1.1
410

511
### Patch Changes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"use strict";
2+
3+
const fs = require("fs");
4+
const path = require("path");
5+
const packageJson = require(path.resolve(__dirname, "package.json"));
6+
7+
delete packageJson.scripts;
8+
packageJson.main = packageJson.main.split("/")[1];
9+
packageJson.types = packageJson.types.split("/")[1];
10+
packageJson.name = "persistnsync";
11+
12+
fs.writeFileSync(
13+
path.resolve(__dirname, "dist", "package.json"),
14+
JSON.stringify(packageJson, null, 2),
15+
);
16+

packages/persist-and-sync/package.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
{
22
"name": "persist-and-sync",
33
"author": "Mayank Kumar Chaudhari <https://mayank-chaudhari.vercel.app>",
4-
"version": "1.1.1",
4+
"version": "1.1.2",
55
"description": "Zustand middleware to easily persist and sync Zustand state between tabs and windows",
66
"main": "dist/index.js",
77
"types": "dist/index.d.ts",
88
"repository": {
99
"type": "git",
10-
"url": "git+https://github.com/mayank1513/persist-and-sync.git"
10+
"url": "git+https://github.com/react18-tools/persist-and-sync.git"
1111
},
1212
"bugs": {
13-
"url": "https://github.com/mayank1513/persist-and-sync/issues"
13+
"url": "https://github.com/react18-tools/persist-and-sync/issues"
1414
},
15-
"homepage": "https://github.com/mayank1513/persist-and-sync#readme",
15+
"homepage": "https://github.com/react18-tools/persist-and-sync#readme",
1616
"sideEffects": false,
1717
"license": "MIT",
1818
"scripts": {
19-
"build": "tsc && node createPackageJSON.js",
20-
"publish-package": "cp ../../README.md dist && cd dist && npm publish",
19+
"build": "tsc && node touchup.js",
20+
"publish-package": "cd dist && npm publish && node ../legacy-support.js && npm publish",
2121
"test": "vitest run --coverage"
2222
},
2323
"funding": {
@@ -26,13 +26,13 @@
2626
},
2727
"devDependencies": {
2828
"@testing-library/react": "^14.1.2",
29-
"@types/node": "^20.10.2",
30-
"@vitejs/plugin-react": "^4.2.0",
31-
"@vitest/coverage-v8": "^0.34.6",
29+
"@types/node": "^20.10.5",
30+
"@vitejs/plugin-react": "^4.2.1",
31+
"@vitest/coverage-v8": "^1.1.0",
3232
"jsdom": "^23.0.1",
3333
"octokit": "^3.1.2",
34-
"typescript": "^5.3.2",
35-
"vitest": "^0.34.6",
34+
"typescript": "^5.3.3",
35+
"vitest": "^1.1.0",
3636
"zustand": "^4.4.7"
3737
},
3838
"peerDependencies": {

packages/persist-and-sync/createPackageJSON.js renamed to packages/persist-and-sync/touchup.js

+5
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,8 @@ fs.writeFileSync(
4242
path.resolve(__dirname, "dist", "package.json"),
4343
JSON.stringify(packageJson, null, 2),
4444
);
45+
46+
fs.copyFileSync(
47+
path.resolve(__dirname, "..", "..", "README.md"),
48+
path.resolve(__dirname, "dist", "README.md"),
49+
);

packages/persist-and-sync/vitest.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export default defineConfig({
1111
setupFiles: ["vitest.setup.ts"],
1212
coverage: {
1313
reporter: ["text", "json", "clover", "html"],
14+
include: ["src/**/*.ts"],
1415
},
15-
threads: true,
1616
mockReset: false,
1717
},
1818
});

0 commit comments

Comments
 (0)