Skip to content

Commit b3a2338

Browse files
authored
Merge pull request #6 from react18-tools/standardise
Standardise
2 parents dfadffc + 57eefca commit b3a2338

File tree

24 files changed

+361
-113
lines changed

24 files changed

+361
-113
lines changed
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
22
name: Bug report
33
about: Create a report to help us improve
4-
title: ''
5-
labels: ''
6-
assignees: ''
7-
4+
title: ""
5+
labels: ""
6+
assignees: ""
87
---
98

109
**Describe the bug**
1110
A clear and concise description of what the bug is.
1211

1312
**To Reproduce**
1413
Steps to reproduce the behavior:
14+
1515
1. Go to '...'
1616
2. Click on '....'
1717
3. Scroll down to '....'
@@ -24,15 +24,17 @@ A clear and concise description of what you expected to happen.
2424
If applicable, add screenshots to help explain your problem.
2525

2626
**Desktop (please complete the following information):**
27-
- OS: [e.g. iOS]
28-
- Browser [e.g. chrome, safari]
29-
- Version [e.g. 22]
27+
28+
- OS: [e.g. iOS]
29+
- Browser [e.g. chrome, safari]
30+
- Version [e.g. 22]
3031

3132
**Smartphone (please complete the following information):**
32-
- Device: [e.g. iPhone6]
33-
- OS: [e.g. iOS8.1]
34-
- Browser [e.g. stock browser, safari]
35-
- Version [e.g. 22]
33+
34+
- Device: [e.g. iPhone6]
35+
- OS: [e.g. iOS8.1]
36+
- Browser [e.g. stock browser, safari]
37+
- Version [e.g. 22]
3638

3739
**Additional context**
3840
Add any other context about the problem here.

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
22
name: Feature request
33
about: Suggest an idea for this project
4-
title: ''
5-
labels: ''
6-
assignees: ''
7-
4+
title: ""
5+
labels: ""
6+
assignees: ""
87
---
98

109
**Is your feature request related to a problem? Please describe.**

.github/workflows/publish.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ jobs:
2929
- run: npm i -g pnpm && pnpm i
3030
name: Install dependencies
3131
- name: Publish to NPM
32-
run: pnpm build && pnpm publish-package
33-
# continue on error to publish scoped package name <- by default repo is setup for a non-scoped + scoped package name
34-
continue-on-error: true
32+
run: |
33+
pnpm build && cd dist && npm publish
34+
sed -i -e "s/.*name.*/\t\"name\": \"zustand-sync\",/" package.json && npm publish
35+
sed -i -e "s/.*name.*/\t\"name\": \"sync-zustand\",/" package.json && npm publish
36+
sed -i -e "s/.*name.*/\t\"name\": \"sync-tabs-zustand\",/" package.json && npm publish
3537
env:
3638
NODE_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
*lock.*
1+
*lock.*
2+
*.md

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
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

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
# Zustand Sync Tabs [![Version](https://img.shields.io/npm/v/zustand-sync-tabs.svg?colorB=green)](https://www.npmjs.com/package/zustand-sync-tabs) [![Downloads](https://img.jsdelivr.com/img.shields.io/npm/dt/zustand-sync-tabs.svg)](https://www.npmjs.com/package/zustand-sync-tabs) ![npm bundle size](https://img.shields.io/bundlephobia/minzip/zustand-sync-tabs)
22

3-
> Zustand middleware to easily sync Zustand state between tabs / windows / iframes (Same Origin)
3+
> Zustand middleware to easily sync Zustand state between tabs/windows / iframes (Same Origin)
44
5-
- ✅ 🐙 (465 Bytes gZiped) < 0.5 kB size cross-tab state sharing middleware for zustand
5+
- ✅ 🐙 ~ 1 kB size cross-tab state sharing middleware for Zustand
66
- ✅ Full TypeScript Support
7-
- ✅ solid reliability in 1 writing and n reading tab-scenarios (with changing writing tab)
8-
- ✅ Fire and forget approach of always using the latest state. Perfect for single user systems
7+
- ✅ solid reliability in 1 writing and n reading tab scenarios (with changing writing tab)
8+
- ✅ Fire and forget approach of always using the latest state. Perfect for single-user systems
99
- ✅ Sync Zustand state between multiple browsing contexts
10-
- ✅ Partial state sharing also supported
10+
- ✅ Partial state sharing is also supported
1111

12-
> Checkout `[persistnsync](https://github.com/mayank1513/nextjs-themes/tree/main/packages/persistnsync#readme)` if you are looking for persisting state locally over reload/refresh or after closing site
12+
> Check out `[persist-and-sync](https://github.com/react18-tools/persist-and-sync)` if you are looking for persisting state locally over reload/refresh or after closing the site.
1313
1414
## Install
1515

1616
```bash
1717
$ pnpm add zustand-sync-tabs
18-
# or
18+
```
19+
**or**
20+
21+
```bash
1922
$ npm install zustand-sync-tabs
20-
# or
23+
```
24+
**or**
25+
26+
```bash
2127
$ yarn add zustand-sync-tabs
2228
```
2329

2430
## Usage
2531

26-
Simply add the middleware while creating the store and the rest will be taken care.
32+
Add the middleware while creating the store and the rest will be taken care.
2733

2834
```ts
2935
import { create } from "zustand";
@@ -49,40 +55,43 @@ const useStore = create<MyStore>(
4955

5056
## Advanced - ignore / filter out fields based on regExp
5157

52-
In several cases you might want to exclude several fields from syncing. To support this scenario, we provide a mechanism to exclude fields based on regExp. Just pass `regExpToIgnore` (optional - default -> undefined) in options object.
58+
In several cases you might want to exclude several fields from syncing. To support this scenario, we provide a mechanism to exclude fields based on list of fields or regular expression.
5359

5460
```ts
55-
// to ignore fields containing a slug
56-
persistNSync(
57-
set => ({
58-
count: 0,
59-
slugSomeState: 1,
60-
slugSomeState2: 1,
61-
set: n => set({ count: n }),
62-
}),
63-
{ name: "my-channel", regExpToIgnore: /slug/ },
64-
// or regExpToIgnore: new RegExp('slug')
65-
// Use full power of regExp by adding `i` and `g` flags
66-
),
61+
type SyncTabsOptionsType = {
62+
name: string;
63+
/** @deprecated */
64+
regExpToIgnore?: RegExp;
65+
include?: (string | RegExp)[];
66+
exclude?: (string | RegExp)[];
67+
};
6768
```
6869

69-
For more details about regExp check out - [JS RegExp](https://www.w3schools.com/jsref/jsref_obj_regexp.asp)
70-
71-
### Exact match
72-
73-
For exactly matching a parameter/field use `/^your-field-name$/`. `^` forces match from the first caracter and similarly, `$` forces match until last character.
70+
**Example**
7471

75-
### Ignore multiple fields with exact match
76-
77-
use `regExpToIgnore: /^(field1|field2|field3)$/`
78-
79-
## Roadmap
72+
```typescript
73+
export const useMyStore = create<MyStoreType>()(
74+
syncTabs(
75+
set => ({
76+
count: 0,
77+
_count: 0 /** skipped as it is included in exclude array */,
78+
setCount: count => {
79+
set(state => ({ ...state, count }));
80+
},
81+
set_Count: _count => {
82+
set(state => ({ ...state, _count }));
83+
},
84+
}),
85+
{ name: "example", exclude: ["_count"] },
86+
),
87+
);
88+
```
8089

81-
- [ ] `regExpToInclude` -> once implemented, passing this parameter will sync only matching fields
90+
For more details about regExp check out - [JS RegExp](https://www.w3schools.com/jsref/jsref_obj_regexp.asp)
8291

83-
### 🤩 Don't forger to start [this repo](https://github.com/mayank1513/turborepo-template)!
92+
### 🤩 Don't forget to star [this repo](https://github.com/mayank1513/turborepo-template)!
8493

85-
Want handson 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)
94+
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)
8695

8796
![Alt](https://repobeats.axiom.co/api/embed/6b5fa6a5fbb6affafea042ba0f292ecf9388ef3c.svg "Repobeats analytics image")
8897

examples/nextjs/.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
module.exports = {
22
extends: ["custom/next"],
3+
rules: {
4+
"@typescript-eslint/explicit-function-return-type": "off",
5+
},
36
};

examples/nextjs/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# nextjs
22

3+
## 1.0.2
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [2894d47]
8+
9+
310
## 1.0.1
411

512
### Patch Changes

examples/nextjs/app/NotSyncedCounter.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ export default function NotSyncedCounter() {
77
return (
88
<div className={styles.card}>
99
<h2>Not Synced Counter:</h2>
10-
<button onClick={() => setCount2(_count + 1)}>🖤 {_count}</button>
10+
<button
11+
onClick={() => {
12+
setCount2(_count + 1);
13+
}}
14+
type="button">
15+
🖤 {_count}
16+
</button>
1117
</div>
1218
);
1319
}

examples/nextjs/app/OpenNewTab.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
"use client";
22
export default function OpenNewTab() {
33
return (
4-
<button className="btn btn-outline mt-4" onClick={() => window.open(".", "_blank")}>
4+
<button
5+
className="btn btn-outline mt-4"
6+
onClick={() => window.open(".", "_blank")}
7+
type="button">
58
Open in new tab/window
69
</button>
710
);

0 commit comments

Comments
 (0)