Skip to content

Commit 6861e81

Browse files
committed
Merge branch 'dev' into minzo-readme-19.0
2 parents 24fa496 + cdfdc5e commit 6861e81

File tree

90 files changed

+2345
-805
lines changed

Some content is hidden

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

90 files changed

+2345
-805
lines changed

.babelrc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
2-
"presets": [
3-
"airbnb"
4-
],
2+
"presets": ["airbnb", "@babel/preset-typescript"],
53
"plugins": ["@emotion"]
64
}

.eslintrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
"airbnb",
44
"plugin:jest/recommended",
55
"plugin:@typescript-eslint/eslint-recommended",
6-
"plugin:@typescript-eslint/recommended"
6+
"plugin:@typescript-eslint/recommended",
7+
"plugin:testing-library/react", // added in for RTL tests
8+
"plugin:jest-dom/recommended" // added in for RTL tests
79
],
810
"root": true,
9-
"plugins": ["jest", "react", "react-hooks", "@typescript-eslint"],
11+
"plugins": ["jest", "react", "react-hooks", "@typescript-eslint", "testing-library", "jest-dom"],
1012
"rules": {
1113
"arrow-parens": [2, "as-needed"],
1214
"import/no-unresolved": "off",

demo-app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"react": "^18.1.0",
3232
"react-dom": "^18.1.0",
3333
"react-router-dom": "^6.3.0",
34-
"ts-node": "^10.4.0"
34+
"ts-node": "^10.4.0",
35+
"use-immer": "^0.9.0"
3536
}
3637
}

demo-app/src/client/Components/Buttons.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import Increment from './Increment';
33

4-
function Buttons():JSX.Element {
4+
function Buttons(): JSX.Element {
55
const buttons = [];
66
for (let i = 0; i < 4; i++) {
77
buttons.push(<Increment key={i} />);
@@ -20,4 +20,3 @@ function Buttons():JSX.Element {
2020
}
2121

2222
export default Buttons;
23-
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React, {useState, createContext} from 'react';
2+
import IncrementWithMoreHooks from './IncrementWithMoreHooks';
3+
4+
/**
5+
* This component as well as IncrementWithMoreHooks were made to show where data for different
6+
* hooks show up in the react fiber tree.
7+
*/
8+
9+
/**
10+
* This file is a JSX file, not a TSX file, on purpose. The code won't be converted to common JS
11+
* before being bundled by webpack. There were some errors that weren't showing up for the other
12+
* Increment.tsx file based on how webpack uglifies ES6 files. Maintaining this as a JSX file
13+
* will help check for these types of issues.
14+
*/
15+
16+
/**
17+
* How Reactime extracts useState data and what would have to be done
18+
* to extract useContext and useReducer data:
19+
*
20+
* When extracting a functional component's useState data from the fiber tree in the backend of
21+
* Reactime, said data is stored on said component's fiber tree node at its memoizedState property,
22+
* which is a linked list with each node holding data for each useState invocation (some but
23+
* not all other hooks also store nodes with data here). Each useState memoizedState node includes
24+
* the variable (e.g. user) and its corresponding dispatch function (e.g. setUser). This dispatch
25+
* function is required to use Reactime's timeJump feature.
26+
*
27+
* useContext data is stored on the property "dependencies", and only the data passed into the
28+
* value attritibute of the 'context'.Provider element will be there. For tripContext.Provider,
29+
* we pass down "trip" without "setTrip", so we won't have access to the 'trip' dispatch function
30+
* in the "IncrementWithMoreHooks" component, meaning Reactime's timeJump won't work without
31+
* finding the 'trip' dispatch function by coming into this component where useState was invoked and
32+
* storing it in the appropriate place. This is easy enough for useState variables, but useContext
33+
* is commonly used with useReducer which is an entirely different beast.
34+
*
35+
* I advise solving the puzzle of making useReducer work with the timeJump functionality before
36+
* integrating other hooks. Look at time jumping in the Redux dev tools chrome extension for
37+
* inspiration, because you essentially need to recreate that within Reactime.
38+
*/
39+
40+
// userInCreateContext is different from 'user' to see where this variable name showed up in the AST
41+
export const userContext = createContext({ userInCreateContext: 'null', setUser: undefined });
42+
export const tripContext = createContext({ trip: 'null', setTrip: undefined });
43+
44+
const ButtonsWithMoreHooks = () => {
45+
const [user, setUser] = useState('null');
46+
const userValue = { user, setUser };
47+
const [trip, setTrip ] = useState('Hawaii');
48+
const tripValue = { trip };
49+
50+
return (
51+
<div className='buttons' key='increment container'>
52+
<userContext.Provider value={userValue} key="userContext Provider">
53+
<tripContext.Provider value={tripValue} key="tripContext Provider">
54+
<IncrementWithMoreHooks key={'IncrementWithMoreHooks'} />
55+
</tripContext.Provider>
56+
</userContext.Provider>
57+
</div>
58+
);
59+
}
60+
61+
export default ButtonsWithMoreHooks;

0 commit comments

Comments
 (0)