|
| 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; |
0 commit comments