Skip to content

Commit f5cc313

Browse files
authored
Merge pull request #88 from oslabs-beta/staging
Staging
2 parents 1b0180d + 47448ab commit f5cc313

File tree

6 files changed

+23
-79
lines changed

6 files changed

+23
-79
lines changed

src/app/components/Action.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface ActionProps {
3939
const Action = (props: ActionProps): unknown => {
4040
const {
4141
selected, last, index, sliderIndex, dispatch, displayName, componentName,
42-
componentData, state, viewIndex, handleOnkeyDown, key,
42+
componentData, state, viewIndex, handleOnkeyDown,
4343
} = props;
4444

4545
/**

src/app/containers/MainContainer.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function MainContainer(): any {
8484
// if viewIndex is -1, then use the sliderIndex instead
8585
const snapshotView = viewIndex === -1 ? snapshots[sliderIndex] : snapshots[viewIndex];
8686
// gabi :: cleannign hierarchy and snapshotView from stateless data
87-
const statelessCleanning = (
87+
const statelessCleaning = (
8888
obj:{
8989
name?:string;
9090
componentData?:object;
@@ -102,32 +102,24 @@ function MainContainer(): any {
102102
if (newObj.state === 'stateless') {
103103
delete newObj.state;
104104
}
105-
if (newObj.state && newObj.state.hooksState) {
106-
if (Array.isArray(newObj.state.hooksState)) {
107-
newObj.state.hooksState.forEach(s => {
108-
delete s.componentData;
109-
});
110-
}
111-
}
112-
113105
if (newObj.stateSnaphot) {
114-
newObj.stateSnaphot = statelessCleanning(obj.stateSnaphot);
106+
newObj.stateSnaphot = statelessCleaning(obj.stateSnaphot);
115107
}
116108
if (newObj.children) {
117109
newObj.children = [];
118110
if (obj.children.length > 0) {
119111
obj.children.forEach((element:{state?:object|string, children?:[]}) => {
120112
if (element.state !== 'stateless' || element.children.length > 0) {
121-
const clean = statelessCleanning(element);
113+
const clean = statelessCleaning(element);
122114
newObj.children.push(clean);
123115
}
124116
});
125117
}
126118
}
127119
return newObj;
128120
};
129-
const snapshotDisplay = statelessCleanning(snapshotView);
130-
const hierarchyDisplay = statelessCleanning(hierarchy);
121+
const snapshotDisplay = statelessCleaning(snapshotView);
122+
const hierarchyDisplay = statelessCleaning(hierarchy);
131123
return (
132124
<div className="main-container">
133125
<HeadContainer />

src/backend/linkFiber.ts

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,8 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
111111
treeBaseDuration,
112112
} = currentFiber;
113113

114-
<<<<<<< HEAD
115114
let newState: any = {};
116115
let componentData: ComponentData = {};
117-
=======
118-
let newState: any;
119-
let componentData: ComponentData = {};
120-
/* = {
121-
index: -1,
122-
actualDuration: 0,
123-
actualStartTime: 0,
124-
selfBaseDuration: 0,
125-
treeBaseDuration: 0,
126-
};
127-
*/
128-
>>>>>>> master
129116
let componentFound = false;
130117

131118
// Check if node is a stateful setState component
@@ -149,16 +136,14 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
149136
const hooksNames = getHooksNames(elementType.toString());
150137
hooksStates.forEach((state, i) => {
151138
hooksIndex = componentActionsRecord.saveNew(state.state, state.component);
139+
componentData.hooksIndex = hooksIndex;
152140
if (newState && newState.hooksState) {
153-
newState.hooksState.push({ [hooksNames[i]]: state.state, componentData: { index: hooksIndex } });
154-
// newState.hooksState.push([{ [hooksNames[i]]: state.state }, hooksIndex]);
141+
newState.hooksState.push({ [hooksNames[i]]: state.state });
155142
} else if (newState) {
156-
newState.hooksState = [{ [hooksNames[i]]: state.state, componentData: { index: hooksIndex } }];
157-
// newState.hooksState = [{ [hooksNames[i]]: state.state }, hooksIndex];
143+
newState.hooksState = [{ [hooksNames[i]]: state.state }];
158144
} else {
159-
// newState = { hooksState: [{ [hooksNames[i]]: state.state }, hooksIndex] };
160145
newState = { hooksState: [] };
161-
newState.hooksState.push({ [hooksNames[i]]: state.state, componentData: { index: hooksIndex } });
146+
newState.hooksState.push({ [hooksNames[i]]: state.state });
162147
}
163148
componentFound = true;
164149
});
@@ -182,10 +167,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
182167

183168
let newNode = null;
184169
// We want to add this fiber node to the snapshot
185-
<<<<<<< HEAD
186-
=======
187170
// const snapshotState = newState.state || newState.hooksState;
188-
>>>>>>> master
189171
if (componentFound || newState === 'stateless') {
190172
if (fromSibling) {
191173
newNode = tree.addSibling(newState,
@@ -196,7 +178,7 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
196178
elementType ? elementType.name : 'nameless',
197179
componentData);
198180
}
199-
if (newState !== 'stateless') console.log('state updated:', newState);
181+
// if (newState !== 'stateless') console.log('state updated:', newState);
200182
} else {
201183
newNode = tree;
202184
}
@@ -229,10 +211,6 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
229211

230212
function onVisibilityChange(): void {
231213
doWork = !document.hidden;
232-
<<<<<<< HEAD
233-
=======
234-
// console.log('doWork is:', doWork);
235-
>>>>>>> master
236214
}
237215

238216
return () => {
@@ -252,19 +230,18 @@ export default (snap: Snapshot, mode: Mode): ()=>void => {
252230
const reactInstance = devTools ? devTools.renderers.get(1) : null;
253231
fiberRoot = devTools.getFiberRoots(1).values().next().value;
254232
const throttledUpdateSnapshot = throttle(updateSnapShotTree, 140);
255-
256233
document.addEventListener('visibilitychange', onVisibilityChange);
257234
if (reactInstance && reactInstance.version) {
258235
devTools.onCommitFiberRoot = (function (original) {
259236
return function (...args) {
260237
// eslint-disable-next-line prefer-destructuring
261238
fiberRoot = args[1];
262-
console.log('in CFR committed fiber');
239+
// console.log('in CFR committed fiber');
263240
if (doWork) {
264-
console.log('in CFR: updating snapshot');
241+
// console.log('in CFR: updating snapshot');
265242
throttledUpdateSnapshot();
266243
}
267-
console.log('in CFR updated snapshot');
244+
// console.log('in CFR updated snapshot');
268245
return original(...args);
269246
};
270247
}(devTools.onCommitFiberRoot));

src/backend/timeJump.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,13 @@ export default (origin, mode) => {
4545

4646
// Check for hooks state and set it with dispatch()
4747
if (target.state && target.state.hooksState) {
48-
console.log('SNAPSHOT TARGET: ', target);
49-
// const hooksComponent = componentActionsRecord.getComponentByIndex(target.state.hooksState[1]);
5048
target.state.hooksState.forEach(hook => {
51-
console.log('HOOK IS:', JSON.stringify(hook));
52-
if (!hook.componentData) return;
53-
const hooksComponent = componentActionsRecord.getComponentByIndex(hook.componentData.index);
54-
// const [hooksState] = [target.state.hooksState];
55-
delete hook.componentData;
56-
const hooksState = Object.values(hook);
49+
const hooksComponent = componentActionsRecord.getComponentByIndex(target.componentData.hooksIndex);
50+
const hookState = Object.values(hook);
5751
if (hooksComponent && hooksComponent.dispatch) {
58-
// hooksComponent.dispatch(Object.values(target.state.hooksState[0])[0]);
59-
hooksComponent.dispatch(hooksState);
52+
hooksComponent.dispatch(hookState[0]);
6053
}
6154
});
62-
//target.children.forEach(child => jump(child));
63-
6455
}
6556

6657
target.children.forEach(child => {

src/backend/types/backendTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface MsgData {
2828

2929
export interface ComponentData {
3030
index?: number;
31+
hooksIndex?: number;
3132
actualDuration?: number;
3233
actualStartTime?: number;
3334
selfBaseDuration?: number;

src/extension/background.js

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function changeCurrLocation(tabObj, rootNode, index, name) {
8989
return;
9090
// if not, recurse on each one of the children
9191
}
92-
92+
9393
if (rootNode.children) { // Carlos: remove if, redundant
9494
rootNode.children.forEach(child => {
9595
changeCurrLocation(tabObj, child, index, name);
@@ -244,7 +244,7 @@ chrome.runtime.onMessage.addListener((request, sender) => {
244244
tabsObj[tabId].snapshots.splice(1);
245245
// gabi :: reset hierarchy to page initial state
246246
if (tabsObj[tabId].hierarchy) {
247-
//test
247+
// test
248248
tabsObj[tabId].hierarchy.children = [];
249249
// gabi :: reset currParent plus current state
250250
tabsObj[tabId].currParent = 1;
@@ -343,13 +343,11 @@ chrome.tabs.onRemoved.addListener(tabId => {
343343
delete firstSnapshotReceived[tabId];
344344
});
345345

346-
// when a new url is loaded on the same tab, this remove the tabid from the tabsObj, recreate the tab and inject the script
346+
// when a new url is loaded on the same tab, this remove the tabid from the tabsObj, recreate the tab and inject the script
347347
chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
348-
349348
// check if the tab title changed to see if tab need to restart
350-
if (changeInfo && tabsObj[tabId]){
351-
if(changeInfo.title && changeInfo.title !== tabsObj[tabId].title){
352-
349+
if (changeInfo && tabsObj[tabId]) {
350+
if (changeInfo.title && changeInfo.title !== tabsObj[tabId].title) {
353351
// tell devtools which tab to delete
354352
if (portsArr.length > 0) {
355353
portsArr.forEach(bg =>
@@ -367,21 +365,6 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
367365

368366
// recreate the tab on the tabsObj
369367
tabsObj[tabId] = createTabObj(changeInfo.title);
370-
371-
// reinject the script to the tab
372-
chrome.tabs.executeScript(tabId, {
373-
code: `
374-
// Function will attach script to the dom
375-
const injectScript = (file, tag) => {
376-
const htmlBody = document.getElementsByTagName(tag)[0];
377-
const script = document.createElement('script');
378-
script.setAttribute('type', 'text/javascript');
379-
script.setAttribute('src', file);
380-
htmlBody.appendChild(script);
381-
};
382-
injectScript(chrome.runtime.getURL('bundles/backend.bundle.js'), 'body');
383-
`,
384-
});
385368
}
386369
}
387370
});

0 commit comments

Comments
 (0)