Skip to content

Commit

Permalink
module-first setup (#5)
Browse files Browse the repository at this point in the history
* module-first setup

* update README and CHANGELOG

* simplify example

* update CHANGELOG
  • Loading branch information
dai-shi authored Apr 26, 2024
1 parent 96c4c04 commit fbb7aaa
Show file tree
Hide file tree
Showing 30 changed files with 3,640 additions and 8,063 deletions.
2 changes: 1 addition & 1 deletion .codesandbox/ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"buildCommand": "compile",
"sandboxes": ["new", "react-typescript-react-ts"],
"node": "14"
"node": "18"
}
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

39 changes: 39 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* eslint-env node */
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
'plugin:import/typescript',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
'plugin:jsx-a11y/recommended',
'prettier',
],
ignorePatterns: ['dist/'],
settings: {
'import/resolver': {
typescript: true,
},
react: { version: 'detect' },
},
rules: {
'import/no-unresolved': ['error', { ignore: ['use-zustand'] }],
'@typescript-eslint/no-unused-vars': [
'error',
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
},
};
64 changes: 0 additions & 64 deletions .eslintrc.json

This file was deleted.

41 changes: 12 additions & 29 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,19 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
node-version: '14.x'
registry-url: 'https://registry.npmjs.org'

- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Cache dependencies
uses: actions/cache@v1
version: 8.2.0
- uses: actions/setup-node@v3
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install

- name: Test
run: yarn test

- name: Compile
run: yarn run compile

- name: Publish
run: npm publish
node-version: 18
registry-url: 'https://registry.npmjs.org'
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- run: pnpm install --frozen-lockfile
- run: npm test
- run: npm run compile
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
31 changes: 9 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,14 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v1
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
node-version: '14.x'

- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Cache dependencies
uses: actions/cache@v1
version: 8.2.0
- uses: actions/setup-node@v3
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install

- name: Test
run: yarn test
node-version: 18
cache: 'pnpm'
cache-dependency-path: '**/pnpm-lock.yaml'
- run: pnpm install --frozen-lockfile
- run: npm test
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/pnpm-lock.yaml
/dist
4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,31 @@

## [Unreleased]

### Changed

- fix a long-lived bug #6
- Module-first setup #5

## [0.0.4] - 2023-01-30

### Changed

- fix: reduce calling selector for updates #4

## [0.0.3] - 2023-01-30

### Changed

- fix: a bug in #2 #3

## [0.0.2] - 2023-01-29

### Changed

- fix: inline selectors #2

## [0.0.1] - 2022-10-16

### Added

- Initial release
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# use-zustand

[![CI](https://img.shields.io/github/actions/workflow/status/dai-shi/use-zustand/ci.yml?branch=main)](https://github.com/dai-shi/use-zustand/actions?query=workflow%3ACI)
[![CI](https://img.shields.io/github/actions/workflow/status/zustandjs/use-zustand/ci.yml?branch=main)](https://github.com/zustandjs/use-zustand/actions?query=workflow%3ACI)
[![npm](https://img.shields.io/npm/v/use-zustand)](https://www.npmjs.com/package/use-zustand)
[![size](https://img.shields.io/bundlephobia/minzip/use-zustand)](https://bundlephobia.com/result?p=use-zustand)
[![discord](https://img.shields.io/discord/627656437971288081)](https://discord.gg/MrQdmzd)
Expand Down Expand Up @@ -65,11 +65,11 @@ The [examples](examples) folder contains working examples.
You can run one of them with

```bash
PORT=8080 yarn run examples:01_typescript
PORT=8080 yarn run examples:01_counter
```

and open <http://localhost:8080> in your web browser.

You can also try them in codesandbox.io:
[01](https://codesandbox.io/s/github/dai-shi/use-zustand/tree/main/examples/01_typescript)
[02](https://codesandbox.io/s/github/dai-shi/use-zustand/tree/main/examples/02_suspense)
[01](https://codesandbox.io/s/github/zustandjs/use-zustand/tree/main/examples/01_counter)
[02](https://codesandbox.io/s/github/zustandjs/use-zustand/tree/main/examples/02_suspense)
7 changes: 0 additions & 7 deletions __tests__/01_basic_spec.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "use-zustand-example",
"version": "0.1.0",
"name": "example",
"version": "0.0.0",
"private": true,
"type": "commonjs",
"dependencies": {
"@types/react": "latest",
"@types/react-dom": "latest",
"react": "experimental",
"react-dom": "experimental",
"react": "beta",
"react-dom": "beta",
"react-scripts": "latest",
"typescript": "latest",
"use-zustand": "latest",
Expand All @@ -17,11 +18,5 @@
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>use-zustand example</title>
<title>example</title>
</head>
<body>
<div id="app"></div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from 'react';

import { createStore } from 'zustand/vanilla';
import { useZustand } from 'use-zustand';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { createRoot } from 'react-dom/client';

import App from './App';
import App from './app';

const ele = document.getElementById('app');
if (ele) {
Expand Down
17 changes: 6 additions & 11 deletions examples/02_suspense/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"name": "use-zustand-example",
"version": "0.1.0",
"name": "example",
"version": "0.0.0",
"private": true,
"type": "commonjs",
"dependencies": {
"@types/react": "latest",
"@types/react-dom": "latest",
"react": "experimental",
"react-dom": "experimental",
"react": "beta",
"react-dom": "beta",
"react-scripts": "latest",
"typescript": "latest",
"use-zustand": "latest",
Expand All @@ -17,11 +18,5 @@
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
}
2 changes: 1 addition & 1 deletion examples/02_suspense/public/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<html>
<head>
<title>use-zustand example</title>
<title>example</title>
</head>
<body>
<div id="app"></div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="react/experimental" />
/// <reference types="react/canary" />

import React, { Suspense, use, useTransition } from 'react';
import { Suspense, use, useTransition } from 'react';

import { createStore } from 'zustand/vanilla';
import { useZustand } from 'use-zustand';
Expand Down Expand Up @@ -34,10 +34,9 @@ const Post = () => {

const App = () => {
const [isPending, startTransition] = useTransition();
const fetchPostOrig = useZustand(postStore, (state) => state.fetchPost);
const fetchPost = (id: number) => {
startTransition(() => {
fetchPostOrig(id);
postStore.getState().fetchPost(id);
});
};
return (
Expand Down
2 changes: 1 addition & 1 deletion examples/02_suspense/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { createRoot } from 'react-dom/client';

import App from './App';
import App from './app';

const ele = document.getElementById('app');
if (ele) {
Expand Down
Loading

0 comments on commit fbb7aaa

Please sign in to comment.