Skip to content

Commit 996cbe7

Browse files
authored
Merge pull request #72 from crperezt/feature4
Adds backend types module; refactors fiberLink to Typescript.
2 parents 805ddb2 + c424f6a commit 996cbe7

File tree

10 files changed

+457
-95
lines changed

10 files changed

+457
-95
lines changed

.eslintrc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
2-
"extends": ["airbnb", "plugin:jest/recommended"],
2+
"extends": [
3+
"airbnb",
4+
"plugin:jest/recommended",
5+
"plugin:@typescript-eslint/eslint-recommended",
6+
"plugin:@typescript-eslint/recommended"],
37
"root": true,
4-
"plugins": ["jest", "react", "react-hooks"],
8+
"plugins": ["jest", "react", "react-hooks", "@typescript-eslint"],
59
"rules": {
610
"arrow-parens": [2, "as-needed"],
711
"import/no-unresolved": "off",

package-lock.json

Lines changed: 233 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
"@types/chrome": "^0.0.119",
6464
"@types/jest": "^26.0.4",
6565
"@types/node": "^12.12.50",
66+
"@typescript-eslint/eslint-plugin": "^3.6.1",
67+
"@typescript-eslint/parser": "^3.6.1",
6668
"babel-loader": "^8.1.0",
6769
"core-js": "^3.6.5",
6870
"css-loader": "^3.6.0",

src/backend/index.ts

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,9 @@ import 'core-js';
66
import 'regenerator-runtime/runtime';
77
import linkFiberStart from './linkFiber';
88
import timeJumpStart from './timeJump';
9+
import { Snapshot, Mode, SnapshotNode, MsgData } from './types/backendTypes'
910
import { Interface } from 'readline';
1011

11-
interface Snapshot{
12-
tree: null;
13-
unfilteredTree: null;
14-
}
15-
16-
interface Mode {
17-
jumping: boolean;
18-
paused: boolean;
19-
locked: boolean;
20-
}
21-
interface Node{
22-
name: string;
23-
state: {
24-
location?: any
25-
}
26-
children: any[]
27-
}
28-
interface Data{
29-
data: {
30-
action: string,
31-
payload: any,
32-
}
33-
}
34-
3512
// * State snapshot object initialized here
3613
const snapShot: Snapshot = {
3714
tree: null,
@@ -44,19 +21,10 @@ const mode: Mode = {
4421
locked: false,
4522
};
4623

47-
48-
// const linkFiber = require('./linkFiber')(snapShot, mode);
49-
// const timeJump = require('./timeJump')(snapShot, mode);
50-
51-
52-
5324
const linkFiber = linkFiberStart(snapShot, mode);
54-
console.log('linkfiber --> ',linkFiber)
5525
const timeJump = timeJumpStart(snapShot, mode);
56-
console.log('timejump --> ' , timeJump )
57-
5826

59-
function getRouteURL(node: Node): string {
27+
function getRouteURL(node: SnapshotNode): string {
6028
if (node.name === 'Router') {
6129
return node.state.location.pathname;
6230
}
@@ -69,15 +37,15 @@ function getRouteURL(node: Node): string {
6937
}
7038

7139
// * Event listener for time-travel actions
72-
window.addEventListener('message', ({ data: { action, payload } } : Data) => {
40+
window.addEventListener('message', ({ data: { action, payload } } : MsgData) => {
7341
switch (action) {
7442
case 'jumpToSnap':
7543
timeJump(payload); // * This sets state with given payload
7644
// Get the pathname from payload and add new entry to browser history
7745
// MORE: https://developer.mozilla.org/en-US/docs/Web/API/History/pushState
7846

7947
// try to modify workInProgress tree from here
80-
window.history.pushState('', '', getRouteURL(payload));
48+
// window.history.pushState('', '', getRouteURL(payload));
8149
break;
8250
case 'setLock':
8351
mode.locked = payload;
@@ -91,6 +59,3 @@ window.addEventListener('message', ({ data: { action, payload } } : Data) => {
9159
});
9260

9361
linkFiber();
94-
95-
// module.exports = linkFiber;
96-
// export default linkFiber;

0 commit comments

Comments
 (0)