-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
12,111 additions
and
28,785 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html> | ||
|
||
<head> | ||
<title>jotai-scheduler example</title> | ||
</head> | ||
|
||
<body> | ||
<div id="app"></div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.app { | ||
display: flex; | ||
flex-direction: column; | ||
height: 100vh; | ||
} | ||
|
||
.header, .footer, .sidebar, .content { | ||
border: 2px solid black; | ||
padding: 20px; | ||
font-size: 24px; | ||
text-align: center; | ||
} | ||
|
||
|
||
.footer { | ||
margin-top: auto; | ||
} | ||
|
||
.body { | ||
display: flex; | ||
flex: 1; | ||
} | ||
|
||
.sidebar { | ||
width: 200px; | ||
} | ||
|
||
.content { | ||
flex: 1; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { atom } from 'jotai'; | ||
import { useAtomValueWithSchedule, useAtomWithSchedule, ImmediatePriority, LowPriority } from 'jotai-scheduler'; | ||
import { useAtom, useAtomValue } from 'jotai'; | ||
|
||
import './App.css'; | ||
|
||
const anAtom = atom(0); | ||
|
||
const simulateHeavyRender = () => { | ||
const start = performance.now(); | ||
while (performance.now() - start < 500) {} | ||
}; | ||
|
||
const Header = () => { | ||
simulateHeavyRender(); | ||
// const num = useAtomValue(anAtom); | ||
console.log('Header Component Render'); | ||
const num = useAtomValueWithSchedule(anAtom, { | ||
priority: LowPriority, | ||
}); | ||
return <div className="header">Header-{num}</div>; | ||
}; | ||
|
||
const Footer = () => { | ||
simulateHeavyRender(); | ||
// const num = useAtomValue(anAtom); | ||
console.log('Footer Component Render'); | ||
const num = useAtomValueWithSchedule(anAtom, { | ||
priority: LowPriority, | ||
}); | ||
return <div className="footer">Footer-{num}</div>; | ||
}; | ||
|
||
const Sidebar = () => { | ||
simulateHeavyRender(); | ||
// const num = useAtomValue(anAtom); | ||
console.log('Sidebar Component Render'); | ||
const num = useAtomValueWithSchedule(anAtom); | ||
return <div className="sidebar">Sidebar-{num}</div>; | ||
}; | ||
|
||
const Content = () => { | ||
simulateHeavyRender(); | ||
// const [num, setNum] = useAtom(anAtom); | ||
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'); | ||
}} | ||
> | ||
+1 | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export function App() { | ||
return ( | ||
<div className="app"> | ||
<Header /> | ||
<div className="body"> | ||
<Sidebar /> | ||
<Content /> | ||
</div> | ||
<Footer /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
import { App } from './App'; | ||
|
||
const ele = document.getElementById('app'); | ||
if (ele) { | ||
createRoot(ele).render(React.createElement(App)); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters