diff --git a/package-lock.json b/package-lock.json index 12fd71a..701375c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1797,7 +1797,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -1818,12 +1819,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -1838,17 +1841,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -1965,7 +1971,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -1977,6 +1984,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -1991,6 +1999,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -1998,12 +2007,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -2022,6 +2033,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -2102,7 +2114,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -2114,6 +2127,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -2199,7 +2213,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -2235,6 +2250,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2254,6 +2270,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -2297,12 +2314,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -2910,6 +2929,11 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" }, + "lodash.clonedeep": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", + "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=" + }, "lodash.memoize": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-3.0.4.tgz", diff --git a/package.json b/package.json index 2c787c9..b102d20 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "eslint-plugin-jsx-a11y": "^6.2.1", "esprima": "^4.0.1", "estraverse": "^4.2.0", - "lodash": "^4.17.11" + "lodash": "^4.17.11", + "lodash.clonedeep": "^4.5.0" } } diff --git a/src/app/components/App.jsx b/src/app/components/App.jsx index 9671a9a..4e67cb1 100644 --- a/src/app/components/App.jsx +++ b/src/app/components/App.jsx @@ -45,11 +45,16 @@ class App extends Component { isPlaying: false, isRecording: false, isPlayingIndex: 0, + id: 0, + action: {}, + state: {}, + prevState: {}, eventTimes: [], }; this.portToExtension = null; this.justStartedRecording = false; + this.hasInjectedScript = false; this.addActionToView = this.addActionToView.bind(this); this.toTheFuture = this.toTheFuture.bind(this); @@ -71,9 +76,14 @@ class App extends Component { this.portToExtension = port; port.onMessage.addListener((msg) => { + // If the user paused the recording session, we return + const { isRecording } = this.state; + if (!isRecording) return; + const newData = { action: msg.action, state: msg.state, + prevState: msg.prevState, id: this.state.data.length, }; @@ -115,7 +125,8 @@ class App extends Component { // functionality to change 'play' button to 'stop' setIsPlaying() { - if (this.state.isPlayingIndex >= this.state.data.length - 1) { + const { isPlayingIndex, data } = this.state; + if (isPlayingIndex >= data.length - 1) { return; } @@ -130,19 +141,24 @@ class App extends Component { setIsRecording() { // This variable will prevent the app from refreshing when we refresh - // the userpage. + // the userpage. this.justStartedRecording = true; - + const { isRecording, hasInjectedScript } = this.state; this.setState(state => ({ isRecording: !state.isRecording, })); + // if we are hitting the pause or re-starting the record session + if (isRecording || hasInjectedScript) return; + + this.setState({ hasInjectedScript: true }); + // we query the active window so we can send it to the background script // so it knows on which URL to run our devtool. chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { const { url } = tabs[0]; - // backgroundPort is a variable made avaiable by the devtools.js + // backgroundPort is a variable made avaiable by the devtools.js backgroundPort.postMessage({ turnOnDevtool: true, url, @@ -151,11 +167,11 @@ class App extends Component { } actionInPlay() { - const { data, isPlayingIndex } = this.state; + const { data, isPlayingIndex, isPlaying } = this.state; setTimeout(() => { this.toTheFuture(); - if (this.state.isPlaying && isPlayingIndex + 1 < data.length - 1) { + if (isPlaying && isPlayingIndex + 1 < data.length - 1) { this.actionInPlay(); } else { this.setState({ isPlaying: false }); @@ -169,10 +185,10 @@ class App extends Component { const { data } = this.state; const actionToView = data.filter(action => e.target.id === String(action.id)); const { - action, id, state, + action, id, state, prevState, } = actionToView[0]; this.setState({ - action, id, state, + action, id, state, prevState, }); } @@ -197,7 +213,7 @@ class App extends Component { // time travel bar change handleBarChange(e) { const { data, isPlayingIndex } = this.state; - const { id, action, state } = data[e.target.value]; + const { id, action, state, prevState } = data[e.target.value]; // forward or past const currentIsPlayingIndex = e.target.value; const forward = currentIsPlayingIndex > isPlayingIndex; @@ -205,6 +221,7 @@ class App extends Component { id, action, state, + prevState, isPlayingIndex: parseInt(currentIsPlayingIndex), }); // Displays to screen @@ -226,18 +243,15 @@ class App extends Component { direction: 'forward', }); - // if (isPlayingIndex >= this.state.data.length - 1) isPlayingIndex = 0; - - const { id, action, state } = data[isPlayingIndex + 1]; + const { id, action, state, prevState } = data[isPlayingIndex + 1]; this.setState(prev => ({ ...prev, id, action, state, + prevState, isPlayingIndex: isPlayingIndex + 1, })); - - console.log('isPlayingIndex', this.state.isPlayingIndex); } // function to travel to the PAST @@ -251,12 +265,13 @@ class App extends Component { direction: 'backwards', }); - const { id, action, state } = data[isPlayingIndex - 1]; + const { id, action, state, prevState } = data[isPlayingIndex - 1]; this.setState(prev => ({ ...prev, id, action, state, + prevState, isPlayingIndex: isPlayingIndex - 1, })); } @@ -275,6 +290,10 @@ class App extends Component { isPlaying: false, isRecording: false, isPlayingIndex: 0, + id: 0, + action: {}, + state: {}, + prevState: {}, }); } @@ -284,12 +303,12 @@ class App extends Component { id, state, data, - setIsPlaying, isPlaying, - setIsRecording, isRecording, filteredData, searchField, + isPlayingIndex, + prevState, eventTimes, } = this.state; @@ -316,6 +335,7 @@ class App extends Component { action={action} id={id} actionState={state} + prevState={prevState} /> )} /> @@ -324,7 +344,7 @@ class App extends Component { toTheFuture={this.toTheFuture} toThePast={this.toThePast} isPlaying={isPlaying} - isPlayingIndex={this.state.isPlayingIndex} + isPlayingIndex={isPlayingIndex} isRecording={isRecording} setIsPlaying={this.setIsPlaying} setIsRecording={this.setIsRecording} @@ -335,4 +355,5 @@ class App extends Component { ); } } + export default App; diff --git a/src/app/components/DetailCards/Effects/EffectsDisplay.jsx b/src/app/components/DetailCards/Effects/EffectsDisplay.jsx index 8869fa7..5c29195 100644 --- a/src/app/components/DetailCards/Effects/EffectsDisplay.jsx +++ b/src/app/components/DetailCards/Effects/EffectsDisplay.jsx @@ -1,23 +1,23 @@ import React from 'react'; -import { DetailsWrapper } from '../../../styles/Details.jsx'; import ReactJson from 'react-json-view'; +import { DetailsWrapper } from '../../../styles/Details.jsx'; // functionality // gets difference from previous state to new state import stateDifference from '../../stateDifference.jsx'; export default function Effects(props) { - console.log('state differnce in effects display IMPORT', stateDifference); - const differenceOfPrevAndNextState = stateDifference([1,2,3], [2,4, 9, 11, {'wow': 1}]) + const { prevState, actionState } = props; + const differenceOfPrevAndNextState = stateDifference(prevState, actionState); + return ( - ); } diff --git a/src/app/components/stateDifference.jsx b/src/app/components/stateDifference.jsx index b0af52c..b2df9ec 100644 --- a/src/app/components/stateDifference.jsx +++ b/src/app/components/stateDifference.jsx @@ -1,39 +1,39 @@ function stateDifference(old, curr) { - - if(typeof(old) === "string" && typeof(curr) === "string") { - if(old === curr) return false; - return curr; - } - else if(typeof(old) === "number" && typeof(curr) === "number") { - if( old === curr) return false; - return curr; - } - else if(typeof(old) !== typeof(curr)) { + + if(typeof(old) === "string" && typeof(curr) === "string") { + if(old === curr) return false; + return curr; + } + else if(typeof(old) === "number" && typeof(curr) === "number") { + if( old === curr) return false; return curr; - } - else if(Array.isArray(old) && Array.isArray(curr)) { - let newArr = []; - for ( let i = 0; i < curr.length; i++){ - if(!old.includes(curr[i])){ - let result = stateDifference(old[i], curr[i]) - if (result) { - newArr.push(result) - } - } - } - return newArr.length > 0 ? newArr : false; - } - else if(typeof(old) === "object" && typeof(curr) === "object") { - let newObj = {} - for ( let prop in curr) { - result = stateDifference(old[prop], curr[prop]) - if (result){ - newObj[prop] = result + } + else if(typeof(old) !== typeof(curr)) { + return curr; + } + else if(Array.isArray(old) && Array.isArray(curr)) { + let newArr = []; + for ( let i = 0; i < curr.length; i++){ + if(!old.includes(curr[i])){ + let result = stateDifference(old[i], curr[i]) + if (result) { + newArr.push(result) } } - return Object.keys(newObj).length === 0 ? false : newObj + } + return newArr.length > 0 ? newArr : false; + } + else if(typeof(old) === "object" && typeof(curr) === "object") { + let newObj = {} + for ( let prop in curr) { + let result = stateDifference(old[prop], curr[prop]) + if (result) { + newObj[prop] = result + } } + return Object.keys(newObj).length === 0 ? false : newObj } +} - export default stateDifference; \ No newline at end of file +export default stateDifference; \ No newline at end of file diff --git a/src/app/container/Details.jsx b/src/app/container/Details.jsx index e1e731d..c005f2f 100644 --- a/src/app/container/Details.jsx +++ b/src/app/container/Details.jsx @@ -18,7 +18,7 @@ export default function Details(props) { // destructuring required info that's being passed down from App.jsx // passing these props onto children const { - action, id, actionState, + action, prevState, actionState, } = props; @@ -34,7 +34,7 @@ export default function Details(props) { /> } + render={props => } /> { if (tab.status !== 'complete' || tab.url.startsWith('chrome')) return; @@ -12,6 +16,8 @@ chrome.tabs.onUpdated.addListener((id, info, tab) => { }); chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { + interceptedUrl = ''; + reqIndex = 0; notifyPorts( { action: 'refresh_devtool', tabId: tabs[0].id }, 'devtools', @@ -19,21 +25,22 @@ chrome.tabs.onUpdated.addListener((id, info, tab) => { }); }); - -let interceptedUrl = ''; function handleRequest(request) { // TODO: filter the request from the webRequest call. if (!interceptedUrl.startsWith(request.initiator)) return { cancel: false }; if (request.type === 'script' && !request.url.startsWith('chrome') - && request.frameId === 0) { - // TODO: adjust comment - // Else we need to check wether or not this contains the react - // library. If it does, we need to send the edit javascript to - // out content script, so it can inject into the page. If it doesnt, - // we need to send the url to our content script so that it can - // add it to the page