Skip to content

Commit 9ce6076

Browse files
refactor: extract business logic (#30)
1 parent 2a40213 commit 9ce6076

File tree

81 files changed

+3523
-1446
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+3523
-1446
lines changed

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
testEnvironment: 'node',
3+
testMatch: ['**/*.test.(ts|tsx)'],
4+
transform: {
5+
'^.+.tsx?$': ['ts-jest', {}],
6+
},
7+
};

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
"prepare": "husky",
1515
"commit": "cz",
1616
"e2e": "playwright test",
17-
"e2e:ui": "playwright test --ui"
17+
"e2e:ui": "playwright test --ui",
18+
"test": "jest",
19+
"test:watch": "jest --watch",
20+
"test:coverage": "jest --coverage"
1821
},
1922
"dependencies": {
2023
"@commitlint/cli": "^19.4.0",
@@ -25,8 +28,11 @@
2528
"@eslint/js": "^9.9.1",
2629
"@mui/icons-material": "^6.0.1",
2730
"@mui/material": "^5.16.7",
31+
"@types/eslint-scope": "^3.7.7",
2832
"ace-builds": "^1.36.0",
2933
"acorn": "^8.12.1",
34+
"acorn-walk": "^8.3.4",
35+
"eslint-scope": "^8.2.0",
3036
"globals": "^15.9.0",
3137
"react": "^18.3.1",
3238
"react-ace": "^12.0.0",
@@ -38,6 +44,7 @@
3844
"@playwright/test": "^1.48.2",
3945
"@semantic-release/changelog": "^6.0.3",
4046
"@semantic-release/git": "^10.0.1",
47+
"@types/jest": "^29.5.14",
4148
"@types/node": "^22.9.0",
4249
"@types/react": "^18.3.4",
4350
"@types/react-dom": "^18.3.0",
@@ -52,9 +59,11 @@
5259
"eslint-plugin-react-hooks": "^4.6.2",
5360
"eslint-plugin-react-refresh": "^0.4.11",
5461
"husky": "^9.1.5",
62+
"jest": "^29.7.0",
5563
"lint-staged": "^15.2.9",
5664
"prettier": "^3.3.3",
5765
"semantic-release": "^24.1.0",
66+
"ts-jest": "^29.2.5",
5867
"typescript": "^5.5.4",
5968
"vite": "^5.4.2"
6069
},

src/components/Modal/Modal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { StyledBox } from './Modal.styled.ts';
44

55
function InfoModal({
66
children,
7-
isOpen,
7+
isOpened,
88
onClose,
9-
}: PropsWithChildren<{ isOpen: boolean; onClose: () => void }>) {
9+
}: PropsWithChildren<{ isOpened: boolean; onClose: () => void }>) {
1010
return (
1111
<Modal
12-
open={isOpen}
12+
open={isOpened}
1313
onClose={onClose}
1414
sx={{
1515
'&.MuiModal-root': {

src/emotion.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ declare module '@emotion/react' {
2121
disabled: string;
2222
enabled: string;
2323
};
24-
task: {
24+
macrotask: {
2525
disabled: string;
2626
enabled: string;
2727
};

src/pages/home/Home.styled.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import TasksQueueBase from './sections/TasksQueue/TasksQueue.tsx';
88
import MicroTasksQueueBase from './sections/MicroTasksQueue/MicroTasksQueue.tsx';
99
import InfoBase from './sections/Info/Info.tsx';
1010
import ConfiguratorBase from './sections/Configurator/Configurator.tsx';
11-
import EventLoopBase from './sections/EventLoop/EventLoop.tsx';
11+
import EventLoopBase from './sections/Wheel/Wheel.tsx';
1212

1313
export const Layout = styled.div`
1414
flex: 1;

src/pages/home/Home.tsx

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
11
import * as Styled from './Home.styled.ts';
2-
import { useEventLoopAnimation } from '../../store/store.ts';
3-
import { isMobile } from '../../utils/isMobile.ts';
4-
import { useEffect } from 'react';
5-
import { EVENT_LOOP_ID } from '../../utils/constants.ts';
62

73
export default function Home() {
8-
const status = useEventLoopAnimation((state) => state.status);
9-
10-
useEffect(() => {
11-
const eventLoopTitleDomNode = document.getElementById(EVENT_LOOP_ID);
12-
if (isMobile() && status === 'running' && eventLoopTitleDomNode) {
13-
eventLoopTitleDomNode.scrollIntoView({
14-
behavior: 'smooth',
15-
block: 'start',
16-
});
17-
}
18-
}, [status]);
19-
204
return (
215
<Styled.Layout>
226
<Styled.Info />
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as Styled from './Callstack.styled.ts';
2+
import InfoModal from 'components/Modal/Modal.tsx';
3+
4+
function CallStackModal({
5+
isOpened,
6+
toggle,
7+
}: {
8+
isOpened: boolean;
9+
toggle: () => void;
10+
}) {
11+
return (
12+
<InfoModal isOpened={isOpened} onClose={toggle}>
13+
<h2>Call stack</h2>
14+
<Styled.CloseIcon onClick={toggle} />
15+
<p>
16+
A call stack is a mechanism for an interpreter to keep track of its
17+
place in a script that calls multiple functions — what function is
18+
currently being run and what functions are called from within that
19+
function, etc.
20+
</p>
21+
<ul>
22+
<li>
23+
When a script calls a function, the interpreter adds it to the call
24+
stack and then starts carrying out the function.
25+
</li>
26+
<li>
27+
Any functions that are called by that function are added to the call
28+
stack further up, and run where their calls are reached.
29+
</li>
30+
<li>
31+
When the current function is finished, the interpreter takes it off
32+
the stack and resumes execution where it left off in the last code
33+
listing.
34+
</li>
35+
<li>
36+
If the stack takes up more space than it was assigned, a "stack
37+
overflow" error is thrown.
38+
</li>
39+
</ul>
40+
</InfoModal>
41+
);
42+
}
43+
44+
export default CallStackModal;

src/pages/home/sections/Callstack/Callstack.styled.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import styled from '@emotion/styled';
22
import { css } from '@emotion/react';
3-
import InfoClosed from '../../../../components/CloseIcon/InfoIcon.tsx';
3+
import InfoClosed from 'components/CloseIcon/InfoIcon.tsx';
44

55
export const Callstack = styled.div`
66
flex: 1;

src/pages/home/sections/Callstack/Callstack.tsx

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,26 @@
1-
import { useEventLists } from '../../../../store/store.ts';
21
import * as Styled from './Callstack.styled.ts';
3-
import InfoIcon from '../../../../components/InfoIcon/InfoIcon.tsx';
4-
import InfoModal from '../../../../components/Modal/Modal.tsx';
5-
import useBoolean from '../../../../utils/useBoolean.tsx';
2+
import InfoIcon from 'components/InfoIcon/InfoIcon.tsx';
3+
import useBoolean from 'utils/hooks/useBoolean.ts';
64
import { Zoom } from '@mui/material';
75
import { List } from '../../Home.styled.ts';
6+
import CallStackModal from './Callstack.modal.tsx';
7+
import { useQueueManagerStore } from 'store/store.ts';
88

99
function CallStack({ className }: { className?: string }) {
10-
const tasks = useEventLists((state) => state.callstack);
11-
const [open, setOpen, setClose] = useBoolean(false);
10+
const tasks = useQueueManagerStore((state) => state.callstack);
11+
const [isOpened, toggle] = useBoolean(false);
1212

1313
return (
1414
<List className={className}>
1515
<span>CallStack</span>
1616
<Styled.Callstack>
17-
<InfoIcon onClick={setOpen} />
18-
{tasks.map(({ display: stack }) => (
19-
<Zoom in key={stack}>
20-
<Styled.CallstackElement>{stack}</Styled.CallstackElement>
17+
<InfoIcon onClick={toggle} />
18+
{tasks.map((task) => (
19+
<Zoom in key={task}>
20+
<Styled.CallstackElement>{task}</Styled.CallstackElement>
2121
</Zoom>
2222
))}
23-
<InfoModal isOpen={open} onClose={setClose}>
24-
<h2>Call stack</h2>
25-
<Styled.CloseIcon onClick={setClose} />
26-
<p>
27-
A call stack is a mechanism for an interpreter to keep track of its
28-
place in a script that calls multiple functions — what function is
29-
currently being run and what functions are called from within that
30-
function, etc.
31-
</p>
32-
<ul>
33-
<li>
34-
When a script calls a function, the interpreter adds it to the
35-
call stack and then starts carrying out the function.
36-
</li>
37-
<li>
38-
Any functions that are called by that function are added to the
39-
call stack further up, and run where their calls are reached.
40-
</li>
41-
<li>
42-
When the current function is finished, the interpreter takes it
43-
off the stack and resumes execution where it left off in the last
44-
code listing.
45-
</li>
46-
<li>
47-
If the stack takes up more space than it was assigned, a "stack
48-
overflow" error is thrown.
49-
</li>
50-
</ul>
51-
</InfoModal>
23+
<CallStackModal isOpened={isOpened} toggle={toggle} />
5224
</Styled.Callstack>
5325
</List>
5426
);

src/pages/home/sections/Configurator/Configurator.data.tsx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ foo1();`,
2929
},
3030
{
3131
title: 'microtasks',
32-
code: `console.log(1);
33-
setTimeout(() => console.log(2), 0);
34-
queueMicrotask(() => console.log(3));
32+
code: `console.log(1);
33+
setTimeout(() => console.log(2), 0);
34+
queueMicrotask(() => console.log(3));
3535
Promise.resolve().then(() => {
3636
console.log(4);
37-
});
38-
setTimeout(() => console.log(5), 500);
37+
});
38+
setTimeout(() => console.log(5), 500);
3939
console.log(6);`,
4040
},
4141
{
4242
title: 'requestAnimationFrame',
43-
code: `console.log(1);
44-
queueMicrotask(() => console.log(2));
45-
requestAnimationFrame(() => console.log(3));
46-
requestAnimationFrame(() => console.log(4));
43+
code: `console.log(1);
44+
queueMicrotask(() => console.log(2));
45+
requestAnimationFrame(() => console.log(3));
46+
requestAnimationFrame(() => console.log(4));
4747
console.log(5);`,
4848
},
4949
{
@@ -60,24 +60,20 @@ function foo3() {
6060
setTimeout(() => {
6161
foo4();
6262
console.log('foo3:1');
63-
}, 0);
64-
queueMicrotask(() => console.log('foo3:2'));
63+
}, 0);
64+
queueMicrotask(() => console.log('foo3:2'));
6565
Promise.resolve().then(() => {
6666
console.log('foo3:3')
67-
});
68-
setTimeout(() => console.log('foo3:4'), 500);
67+
});
68+
setTimeout(() => console.log('foo3:4'), 500);
6969
console.log('foo3:5');
7070
}
7171
function foo4() {
7272
console.log('foo4');
7373
}
74-
function foo5(param1) {
75-
console.log(param1);
76-
}
7774
7875
console.log('global');
79-
setTimeout(() => console.log('global:1'), 500);
80-
foo1();
81-
foo5('foo5:1');`,
76+
setTimeout(() => console.log('global:1'), 500);
77+
foo1();`,
8278
},
8379
];

0 commit comments

Comments
 (0)