Skip to content

Commit a25519f

Browse files
authored
Merge pull request #60 from nmwenz90/tsconversion
Made changes to webpack, created ts files
2 parents 4dd2b0d + 042f627 commit a25519f

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed

dev-reactime/index.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* 'reactime' module has a single export
3+
* @function linkFiber
4+
*/
5+
import 'core-js';
6+
import 'regenerator-runtime/runtime';
7+
import linkFiberStart from './linkFiber';
8+
import timeJumpStart from './timeJump';
9+
import { Interface } from 'readline';
10+
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+
35+
// * State snapshot object initialized here
36+
const snapShot: Snapshot = {
37+
tree: null,
38+
unfilteredTree: null,
39+
};
40+
41+
const mode: Mode = {
42+
jumping: false,
43+
paused: false,
44+
locked: false,
45+
};
46+
47+
48+
// const linkFiber = require('./linkFiber')(snapShot, mode);
49+
// const timeJump = require('./timeJump')(snapShot, mode);
50+
51+
52+
53+
const linkFiber = linkFiberStart(snapShot, mode);
54+
console.log('linkfiber --> ',linkFiber)
55+
const timeJump = timeJumpStart(snapShot, mode);
56+
console.log('timejump --> ' , timeJump )
57+
58+
59+
function getRouteURL(node: Node): string {
60+
if (node.name === 'Router') {
61+
return node.state.location.pathname;
62+
}
63+
if (node.children && node.children.length >= 1) {
64+
const tempNode: any[] = node.children;
65+
for (let index = 0; index < tempNode.length; index += 1) {
66+
return getRouteURL(tempNode[index]); // Carlos: ???
67+
}
68+
}
69+
}
70+
71+
// * Event listener for time-travel actions
72+
window.addEventListener('message', ({ data: { action, payload } } : Data) => {
73+
switch (action) {
74+
case 'jumpToSnap':
75+
timeJump(payload); // * This sets state with given payload
76+
// Get the pathname from payload and add new entry to browser history
77+
// MORE: https://developer.mozilla.org/en-US/docs/Web/API/History/pushState
78+
79+
// try to modify workInProgress tree from here
80+
window.history.pushState('', '', getRouteURL(payload));
81+
break;
82+
case 'setLock':
83+
mode.locked = payload;
84+
break;
85+
case 'setPause':
86+
mode.paused = payload;
87+
break;
88+
default:
89+
break;
90+
}
91+
});
92+
93+
linkFiber();
94+
95+
// module.exports = linkFiber;
96+
// export default linkFiber;

dev-reactime/module.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare module 'core-js';
2+
declare module 'regenerator-runtime/runtime';

webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const config = {
88
app: './src/app/index.tsx',
99
background: './src/extension/background.js',
1010
content: './src/extension/contentScript.js',
11-
backend: './dev-reactime/index.js',
11+
backend: './dev-reactime/index.ts',
1212
},
1313
output: {
1414
path: path.resolve(__dirname, 'src/extension/build/bundles'),

0 commit comments

Comments
 (0)