Skip to content

Commit 368b3e3

Browse files
committed
Readme update
1 parent d969a87 commit 368b3e3

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

README.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@ Note: Uses react canary (19)
55
Our [App.tsx](./src/App.tsx) here calculates factorial of a number, fibonacci sequence and does a bit of arithmetics but it does all that using react (not JS). What I mean by that is:
66
- No function recursion
77
- No loops
8-
- No if-else/ternaries/`&& ||` ternaries
8+
- No if-else/`?:` ternaries/`&& ||` ternaries
99
- No switch-case
1010
- No arithmetic operators (Currently I'm still minus for convinience but that'll change)
1111

12+
![Screenshot](./screenshot.jpg)
13+
14+
1215
## How it works
16+
It's all a blur now. I was in a state of trance when I wrote this. But basically, it uses Suspense and react's ability to get stuck in infinite render/state-update loop to compute things.
17+
18+
Don't want to spend more time on this so if you need more details, feel free to ask in an issue. I'll be happy to explain.
19+
1320

14-
It's all a blur now. I was in a state of trance when I wrote this. But basically, it uses Suspense and react's ability to get stuck in infinite render/state-update loop to calculate things.
21+
## How to run it?
22+
Why would you want to do something like that? But if you're sure you want to...
1523

16-
Don't want to spend more time on this so if you need more details, go through the code or ask me. I'll be happy to explain.
24+
- Clone this thing
25+
- Install dependencies `bun i` (Uses bun because I'm cool like that)
26+
- `bun run dev`
27+
- Open `localhost:5173` in your browser
1728

screenshot.jpg

9.23 KB
Loading

src/program/compute.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const CallElement: FC<{
2828
fn: ReactNode,
2929
children: (result: any) => ReactNode,
3030
}> = ({ fn, children }) => {
31-
const [_, forceUpdate] = useReducer((n) => n + 1, 0)
31+
const [_, forceUpdate] = useReducer((n) => !n, false)
3232
const resolve = useRef((_: any) => {});
3333
const promise = useMemo(() => new Promise((res) => {
3434
resolve.current = res
@@ -53,7 +53,7 @@ export const EvaluateAll: FC<{ fns: ReactNode[] }> = ({ fns }) => {
5353

5454
const resolve = useCallback((result: any, i: number) => {
5555
resultList.current[i] = result;
56-
resultCount.current += 1;
56+
resultCount.current++;
5757
if (resultCount.current === fns.length) {
5858
onReturn(resultList.current);
5959
}

0 commit comments

Comments
 (0)