Skip to content

Commit

Permalink
ci
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Qun committed Aug 24, 2024
1 parent 4e7c523 commit 5c62f25
Show file tree
Hide file tree
Showing 14 changed files with 242 additions and 174 deletions.
8 changes: 4 additions & 4 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/dist
/src/vendor
/pnpm-lock.yaml
/jotai
dist
examples
node_modules
website
31 changes: 31 additions & 0 deletions .github/workflows/lint-and-type.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: lint and type

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '18'
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile --prefer-offline
- name: Prettier
run: pnpm run prettier:ci
- name: Lint
run: pnpm run eslint:ci
- name: Type
run: pnpm run typecheck
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: test

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '18'
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile --prefer-offline
- name: Run Tests
run: pnpm run test
72 changes: 38 additions & 34 deletions examples/demo-01/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,65 +1,69 @@
import { atom } from 'jotai';
import { useAtomValueWithSchedule, useAtomWithSchedule, ImmediatePriority, LowPriority } from 'jotai-scheduler';
import { useAtom, useAtomValue } from 'jotai';
import { atom, useAtom, useAtomValue } from 'jotai'
import {
useAtomValueWithSchedule,
useAtomWithSchedule,
ImmediatePriority,
LowPriority,
} from 'jotai-scheduler'

import './App.css';
import './App.css'

const anAtom = atom(0);
const anAtom = atom(0)

const simulateHeavyRender = () => {
const start = performance.now();
const start = performance.now()
while (performance.now() - start < 500) {}
};
}

const Header = () => {
simulateHeavyRender();
function Header() {
simulateHeavyRender()
// const num = useAtomValue(anAtom);
console.log('Header Component Render');
console.log('Header Component Render')
const num = useAtomValueWithSchedule(anAtom, {
priority: LowPriority,
});
return <div className="header">Header-{num}</div>;
};
})
return <div className="header">Header-{num}</div>
}

const Footer = () => {
simulateHeavyRender();
function Footer() {
simulateHeavyRender()
// const num = useAtomValue(anAtom);
console.log('Footer Component Render');
console.log('Footer Component Render')
const num = useAtomValueWithSchedule(anAtom, {
priority: LowPriority,
});
return <div className="footer">Footer-{num}</div>;
};
})
return <div className="footer">Footer-{num}</div>
}

const Sidebar = () => {
simulateHeavyRender();
function Sidebar() {
simulateHeavyRender()
// const num = useAtomValue(anAtom);
console.log('Sidebar Component Render');
const num = useAtomValueWithSchedule(anAtom);
return <div className="sidebar">Sidebar-{num}</div>;
};
console.log('Sidebar Component Render')
const num = useAtomValueWithSchedule(anAtom)
return <div className="sidebar">Sidebar-{num}</div>
}

const Content = () => {
simulateHeavyRender();
function Content() {
simulateHeavyRender()
// const [num, setNum] = useAtom(anAtom);
console.log('Content Component Render');
console.log('Content Component Render')
const [num, setNum] = useAtomWithSchedule(anAtom, {
priority: ImmediatePriority,
});
})
return (
<div className="content">
<div>Content-{num}</div>
<button
onClick={() => {
setNum((num) => ++num);
console.log('trigger');
setNum((num) => ++num)
console.log('trigger')
}}
>
+1
</button>
</div>
);
};
)
}

export function App() {
return (
Expand All @@ -71,5 +75,5 @@ export function App() {
</div>
<Footer />
</div>
);
)
}
10 changes: 5 additions & 5 deletions examples/demo-01/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { createRoot } from 'react-dom/client';
import { App } from './App';
import React from 'react'
import { createRoot } from 'react-dom/client'
import { App } from './App'

const ele = document.getElementById('app');
const ele = document.getElementById('app')
if (ele) {
createRoot(ele).render(React.createElement(App));
createRoot(ele).render(React.createElement(App))
}
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@
"compile": "microbundle build -f modern,umd --globals react=React --no-compress",
"postcompile": "cp dist/index.modern.mjs dist/index.modern.js && cp dist/index.modern.mjs.map dist/index.modern.js.map",
"prepublishOnly": "pnpm run compile && pnpm run postcompile",
"test": "run-s eslint tsc-test jest",
"eslint": "eslint --ext .js,.ts,.tsx .",
"jest": "jest",
"tsc-test": "tsc --project . --noEmit"
"test": "jest --passWithNoTests",
"eslint": "eslint --no-eslintrc -c .eslintrc.json --fix '**/src/*.{js,jsx,ts,tsx}'",
"eslint:ci": "eslint --no-eslintrc -c .eslintrc.json '**/src/*.{js,jsx,ts,tsx}'",
"prettier": "prettier '**/{examples,src,__tests__,website}/**/*.{js,jsx,ts,tsx,md}' --write",
"prettier:ci": "prettier '**/{examples,src,__tests__,website}/**/*.{js,jsx,ts,tsx,md}' --list-different",
"typecheck": "tsc --project . --noEmit"
},
"prettier": {
"semi": false,
"singleQuote": true
},
"jest": {
"testEnvironment": "jsdom",
Expand Down
6 changes: 3 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const ImmediatePriority = 1;
export const NormalPriority = 2;
export const LowPriority = 3;
export const ImmediatePriority = 1
export const NormalPriority = 2
export const LowPriority = 3
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { useAtomValueWithSchedule } from './useAtomValueWithSchedule';
export { useAtomWithSchedule } from './useAtomWithSchedule';
export { useSetAtomWithSchedule } from './useSetAtomWithSchedule';
export { LowPriority, NormalPriority, ImmediatePriority } from './constants';
export * from './types';
export { useAtomValueWithSchedule } from './useAtomValueWithSchedule'
export { useAtomWithSchedule } from './useAtomWithSchedule'
export { useSetAtomWithSchedule } from './useSetAtomWithSchedule'
export { LowPriority, NormalPriority, ImmediatePriority } from './constants'
export * from './types'
26 changes: 13 additions & 13 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { Atom, useStore } from 'jotai';
import { ImmediatePriority, LowPriority, NormalPriority } from './constants';
import { Atom, useStore } from 'jotai'
import { ImmediatePriority, LowPriority, NormalPriority } from './constants'

export type SetAtom<Args extends unknown[], Result> = (...args: Args) => Result;
export type SetAtom<Args extends unknown[], Result> = (...args: Args) => Result

export type AnyAtom = Atom<unknown>;
export type AnyAtom = Atom<unknown>

export type Store = ReturnType<typeof useStore>;
export type Store = ReturnType<typeof useStore>

export type Listener = () => void;
export type Listener = () => void

export type PriorityLevel =
| typeof ImmediatePriority
| typeof NormalPriority
| typeof LowPriority;
| typeof LowPriority

export type Options = Parameters<typeof useStore>[0] & {
delay?: number;
priority?: PriorityLevel;
};
delay?: number
priority?: PriorityLevel
}

export type Task = {
priority: PriorityLevel;
subscribe: Listener;
};
priority: PriorityLevel
subscribe: Listener
}
Loading

0 comments on commit 5c62f25

Please sign in to comment.