Skip to content

Commit

Permalink
Merge pull request #46 from gadingnst/2.1.0
Browse files Browse the repository at this point in the history
v2.1.0
  • Loading branch information
Gading Nasution authored Dec 17, 2022
2 parents 8619542 + cd4ec67 commit 4e1b152
Show file tree
Hide file tree
Showing 39 changed files with 3,970 additions and 2,231 deletions.
48 changes: 0 additions & 48 deletions .eslintrc.json

This file was deleted.

16 changes: 13 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ jobs:
with:
package-manager: npm
skip-step: all
coverage-file: report.json
base-coverage-file: report.json
coverage-file: packages/swr-global-state/report.json
base-coverage-file: packages/swr-global-state/report.json

build:
name: Build
Expand All @@ -92,11 +92,21 @@ jobs:
size:
name: Build & Generate Size report
if: github.event_name == 'pull_request'
needs: install
runs-on: ubuntu-latest
env:
CI_JOB_NUMBER: 1
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Load node_modules
uses: actions/cache@v1
with:
path: node_modules
key: node_modules-${{ github.event.pull_request.head.sha }}
- uses: andresz1/size-limit-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
skip_step: install
directory: packages/swr-global-state
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
registry-url: https://registry.npmjs.org
- name: Install dependencies
run: npm ci
- name: Checkout to package swr-global-state
run: cd packages/swr-global-state
- name: Build Package
run: npm run build
- name: Publishing Package
Expand Down
36 changes: 34 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
*.log
.DS_Store
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
node_modules
.pnp
.pnp.js

# testing
coverage

# next.js
.next/
out/
build

# output
dist

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# turbo
.turbo

# Test Coverage
coverage
report.json
4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

4 changes: 4 additions & 0 deletions apps/demo/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ['custom']
};
30 changes: 30 additions & 0 deletions apps/demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Getting Started

First, run the development server:

```bash
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn/foundations/about-nextjs) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_source=github.com&utm_medium=referral&utm_campaign=turborepo-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
23 changes: 23 additions & 0 deletions apps/demo/components/GetCount.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import useCount from '../states/stores/count';
import useCountAsync from '../states/stores/count-async';
import useCountPersisted from '../states/stores/count-persisted';

function GetCount() {
const [count] = useCount();
const [countPersist] = useCountPersisted();
const [countAsync] = useCountAsync();

return (
<div>
<p>
Current Count: {count}
<br />
Current Count (Persisted): {countPersist}
<br />
Current Count (Async): {countAsync}
</p>
</div>
);
}

export default GetCount;
34 changes: 34 additions & 0 deletions apps/demo/components/GithubBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function GitHubBadge() {
return (
<div>
<a
href="https://github.com/gadingnst/swr-global-state-demo"
className="github-corner"
aria-label="View source on GitHub"
>
<svg
width="80"
height="80"
viewBox="0 0 250 250"
style={{ fill: '#151513', color: '#fff', position: 'absolute', top: 0, border: 0, right: 0 }}
aria-hidden="true"
>
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z" />
<path
d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
fill="currentColor"
className="octo-arm"
style={{ transformOrigin: '130px 106px' }}
/>
<path
d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
fill="currentColor"
className="octo-body"
/>
</svg>
</a>
</div>
);
}

export default GitHubBadge;
35 changes: 35 additions & 0 deletions apps/demo/components/SetCount.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import useCount from '../states/stores/count';
import useCountPersisted from '../states/stores/count-persisted';
import useCountAsync from '../states/stores/count-async';

function SetCount() {
const [, setCount] = useCount();
const [, setCountPersisted] = useCountPersisted();
const [, setCountAsync] = useCountAsync();

const decreaseCount = () => {
setCount(prev => prev - 1);
setCountPersisted(prev => prev - 1);
setCountAsync(prev => prev - 1);
};

const increaseCount = () => {
setCount(prev => prev + 1);
setCountPersisted(prev => prev + 1);
setCountAsync(prev => prev + 1);
};

return (
<div>
<button onClick={decreaseCount}>
(-) Decrease Count
</button>
&nbsp;
<button onClick={increaseCount}>
(+) Increase Count
</button>
</div>
);
}

export default SetCount;
5 changes: 5 additions & 0 deletions apps/demo/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
6 changes: 6 additions & 0 deletions apps/demo/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
reactStrictMode: true,
experimental: {
transpilePackages: ['swr-global-state']
}
};
27 changes: 27 additions & 0 deletions apps/demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "swr-global-state-demo",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"swr-global-state": "*",
"next": "13.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@types/node": "^17.0.12",
"@types/react": "^18.0.22",
"@types/react-dom": "^18.0.7",
"eslint": "7.32.0",
"eslint-config-custom": "*",
"tsconfig": "*",
"typescript": "^4.5.3"
}
}
13 changes: 13 additions & 0 deletions apps/demo/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import '../styles/globals.css';
import type { AppProps } from 'next/app';
import GitHubBadge from '../components/GithubBadge';

function MyApp({ Component, pageProps }: AppProps) {
return (
<>
<GitHubBadge />
<Component {...pageProps} />
</>
);
}
export default MyApp;
60 changes: 60 additions & 0 deletions apps/demo/pages/about.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* eslint-disable @next/next/no-img-element */

import Link from 'next/link';
import useCount from '../states/stores/count';
import useCountPersisted from '../states/stores/count-persisted';
import useCountAsync from '../states/stores/count-async';
import useData from '../states/stores/data';

const About = () => {
const [count] = useCount();
const [countPersist] = useCountPersisted();
const [countAsync] = useCountAsync();
const { data, login, logout, error } = useData();

const renderData = () => {
let msg = 'Loading...';
if (error) {
msg = 'You must login before see the data';
} else if (data) {
msg = `By: ${data?.maintaner || '-'}`;
}
return (
<p style={{ fontSize: 14 }}>
{msg}
</p>
);
};

return (
<div className="App">
<header className="App-header">
<img src="/logo.svg" className="App-logo" alt="logo" />
<p style={{ color: 'aquamarine' }}>
This is About Page.
</p>
{renderData()}
<div style={{ display: 'flex' }}>
<button onClick={login} style={{ marginRight: 10 }}>
Login
</button>
<button onClick={logout}>
Destroy Data
</button>
</div>
<p>
Count from Home: {count}
<br />
Count from Home (Persisted): {countPersist}
<br />
Count from Home (Async): {countAsync}
</p>
<Link className="App-link" href="/">
Go To Home
</Link>
</header>
</div>
);
};

export default About;
Loading

0 comments on commit 4e1b152

Please sign in to comment.