Skip to content

Commit ccff073

Browse files
authored
Merge pull request #129 from open-source-labs/d3-implementation
D3 implementation
2 parents d6b3341 + 9e46b7c commit ccff073

26 files changed

+1975
-1278
lines changed

.eslintrc

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
{
22
"extends": ["airbnb", "plugin:jest/recommended"],
33
"root": true,
4-
"plugins": ["jest"],
4+
"plugins": ["jest", "react"],
5+
"rules": {
6+
"arrow-parens": [2, "as-needed"]
7+
},
58
"env": {
9+
"es6": true,
610
"jest/globals": true,
711
"browser": true,
812
"webextensions": true
913
},
1014
"globals": {
15+
"Atomics": "readonly",
16+
"SharedArrayBuffer": "readonly",
1117
"fetch": false
1218
},
13-
"rules": {
14-
"arrow-parens": [2, "as-needed"]
19+
"parserOptions": {
20+
"ecmaFeatures": {
21+
"jsx": true
22+
},
23+
"ecmaVersion": 2018,
24+
"sourceType": "module"
25+
},
26+
"settings": {
27+
"import/no-unresolved": "off"
1528
}
16-
}
29+
}

package-lock.json

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

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@
4141
"css-loader": "^3.2.0",
4242
"enzyme": "^3.10.0",
4343
"enzyme-adapter-react-16": "^1.14.0",
44-
"eslint": "^5.16.0",
45-
"eslint-config-airbnb": "^17.1.1",
44+
"eslint": "^6.5.1",
45+
"eslint-config-airbnb": "^18.0.1",
4646
"eslint-plugin-import": "^2.18.2",
4747
"eslint-plugin-jest": "^22.15.0",
4848
"eslint-plugin-jsx-a11y": "^6.2.3",
49-
"eslint-plugin-react": "^7.14.3",
50-
"jest": "^24.8.0",
49+
"eslint-plugin-react": "^7.15.1",
50+
"eslint-plugin-react-hooks": "^1.7.0",
51+
"jest": "^24.9.0",
5152
"jest-cli": "^24.8.0",
53+
"jest-runner-eslint": "^0.7.4",
5254
"node-sass": "^4.12.0",
5355
"sass": "^1.22.9",
5456
"sass-loader": "^7.2.0",
@@ -64,6 +66,7 @@
6466
"d3-tip": "^0.9.1",
6567
"d3-zoom": "^1.8.3",
6668
"immer": "^3.2.0",
69+
"jest-runner": "^24.9.0",
6770
"jsondiffpatch": "^0.3.11",
6871
"prop-types": "^15.7.2",
6972
"rc-slider": "^8.6.13",

package/__tests__/astParser.test.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// Test 1: Should take in a function definition with 1 hook and return an object with the getter/setter
1+
// import { configure, shallow } from 'enzyme';
2+
3+
// Test 1: Should take in a function definition with 1 hook
4+
// and return an object with the getter / setter
25
// EXAMPLE INPUT FOR TEST
36
/**
47
* function UseStateHookTest() {
@@ -22,7 +25,14 @@
2225
* }
2326
*/
2427

25-
// TEST 2: Should take in multiple function definitions with hooks and return an object with all 4 properties
26-
// TEST 3: Should ignore any non-hook definitions
27-
// Test 4: Should return an empty object if no hooks found
28-
// Test 5: Should throw an error if input is invalid javascript
28+
// TEST 2: Should take in multiple function definitions
29+
// with hooks and return an object with all 4 properties
30+
// TEST 3: Should ignore any non-hook definitions
31+
// Test 4: Should return an empty object if no hooks found
32+
// Test 5: Should throw an error if input is invalid javascript
33+
34+
describe('placeholder', () => {
35+
it.skip('placeholder for tests', () => {
36+
expect(1 + 1).toEqual(2);
37+
});
38+
});

package/__tests__/linkFiber.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable react/jsx-filename-extension */
2-
import React, { Component, useState } from 'react';
2+
import React, { Component } from 'react';
33
import { render } from 'react-dom';
44

55
const linkFiberRequire = require('../linkFiber');
@@ -20,12 +20,12 @@ class App extends Component {
2020
}
2121
}
2222

23-
// Need to create a functioanl component instance to test
23+
// Need to create a functioanl component instance to test
2424
// Would need to be revised but here's the gist
2525
// const funcComponent = () => {
26-
// const [ number, setNumber ] = useState(0);
27-
// const newNumber = setNumber(1);
28-
26+
// const [ number, setNumber ] = useState(0);
27+
// const newNumber = setNumber(1);
28+
2929
// return (
3030
// <div>{newNumber}</div>
3131
// )

package/__tests__/timeJump.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable max-classes-per-file */
12
const timeJumpRequire = require('../timeJump');
23

34
class Component {
@@ -19,8 +20,8 @@ class FiberNode {
1920
}
2021
}
2122

22-
// MVP FEATURE: Additional Testing
23-
// Testing for useState and useContext
23+
// MVP FEATURE: Additional Testing
24+
// Testing for useState and useContext
2425

2526

2627
describe('unit testing for timeJump.js', () => {

package/astParser.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
const acorn = require('acorn');
22
const jsx = require('acorn-jsx');
3+
34
const JSXParser = acorn.Parser.extend(jsx());
45

56
// Helper function to grab the getters/setters from `elementType`
67
module.exports = elementType => {
78
// Initialize empty object to store the setters and getter
8-
let ast = JSXParser.parse(elementType);
9+
let ast = JSXParser.parse(elementType);
910
const hookState = {};
1011
// All module exports will always start off as a single 'FunctionDeclaration' type
1112
while (Object.hasOwnProperty.call(ast, 'body')) {
@@ -34,4 +35,4 @@ module.exports = elementType => {
3435
});
3536
}
3637
return hookState;
37-
}
38+
};

package/linkFiber.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ module.exports = (snap, mode) => {
1313

1414
function sendSnapshot() {
1515
// don't send messages while jumping or while paused
16-
// DEV: So that when we are jumping to an old snapshot it wouldn't think we want to create new snapshots
16+
// DEV: So that when we are jumping to an old snapshot it
17+
// wouldn't think we want to create new snapshots
1718
if (mode.jumping || mode.paused) return;
1819
const payload = snap.tree.getCopy();
1920
// console.log('payload', payload);
@@ -83,7 +84,7 @@ module.exports = (snap, mode) => {
8384

8485
function createTree(currentFiber, tree = new Tree('root')) {
8586
if (!currentFiber) return tree;
86-
87+
8788
const {
8889
sibling,
8990
stateNode,
@@ -103,9 +104,9 @@ module.exports = (snap, mode) => {
103104
// Check if the component uses hooks
104105
if (memoizedState && Object.hasOwnProperty.call(memoizedState, 'baseState')) {
105106
// Traverse through the currentFiber and extract the getters/setters
106-
astHooks = astParser(elementType);
107-
saveState(astHooks);
108-
// Create a traversed property and assign to the evaluated result of
107+
astHooks = astParser(elementType);
108+
saveState(astHooks);
109+
// Create a traversed property and assign to the evaluated result of
109110
// invoking traverseHooks with memoizedState
110111
memoizedState.traversed = traverseHooks(memoizedState);
111112
nextTree = tree.appendChild(memoizedState);
@@ -131,7 +132,7 @@ module.exports = (snap, mode) => {
131132
} = container;
132133
// only assign internal rootp if it actually exists
133134
fiberRoot = _internalRoot || _reactRootContainer;
134-
135+
135136
updateSnapShotTree();
136137
// send the initial snapshot once the content script has started up
137138
window.addEventListener('message', ({ data: { action } }) => {
@@ -145,5 +146,5 @@ module.exports = (snap, mode) => {
145146
// return getNextImport('./UseStateHook');
146147
// return 'Testing outside';
147148
// const OtherComponent = loadable(() => import('./OtherComponent'))
148-
}
149-
};
149+
};
150+
};

package/tree.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class Tree {
3030
getCopy(copy = new Tree('root', true)) {
3131
// copy state of children
3232
copy.children = this.children.map(
33-
child => new Tree(child.component.state || child.component.traversed, true, child.component.constructor.name),
33+
child => new Tree(child.component.state
34+
|| child.component.traversed, true, child.component.constructor.name),
3435
);
3536

3637
// copy children's children recursively
@@ -40,8 +41,8 @@ class Tree {
4041

4142
// print out the tree in the console
4243
// DEV: Process may be different for useState components
43-
// BUG FIX: Don't print the Router as a component
44-
// Change how the children are printed
44+
// BUG FIX: Don't print the Router as a component
45+
// Change how the children are printed
4546
print() {
4647
const children = ['children: '];
4748
// DEV: What should we push instead for components using hooks (it wouldn't be state)

src/app/__tests__/Chart.test.jsx

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
const TestRunner = require("jest-runner")
1+
// import TestRunner from 'jest-runner';
22

33
// Unit Test Cases for Charts
4-
// description: lifecycle methods
5-
// Component should call make3dTree upon mounting
6-
// object 'root' should be a deep clone of the snapshot
7-
// i.e.: this.props.snapshot !== root
4+
// description: lifecycle methods
5+
// Component should call make3dTree upon mounting
6+
// object 'root' should be a deep clone of the snapshot
7+
// i.e.: this.props.snapshot !== root
88

9-
// description: maked3Tree
10-
// Should call function 'removed3tree' only once
11-
// Should call appropriate function upon triggering a certain event on the tooltip div
12-
// i.e.:
13-
// 'mouseover' event -> 'tipMouseover' function
14-
// 'mouseout' event -> 'tipMouseout' function
15-
// Should call appropriate function upon triggering a certain event on a node (nested under the 'update' function)
16-
// i.e.:
17-
// 'mouseover' event -> 'mouseover' function
18-
// 'mouseout' event -> 'mouseout' function
19-
// 'click' event -> 'click' function
20-
// Should call function 'update' at least once
9+
// description: maked3Tree
10+
// Should call function 'removed3tree' only once
11+
// Should call appropriate function upon triggering a certain event on the tooltip div
12+
// i.e.:
13+
// 'mouseover' event -> 'tipMouseover' function
14+
// 'mouseout' event -> 'tipMouseout' function
15+
// Should call appropriate function upon triggering a certain event on a node
16+
// (nested under the 'update' function)
17+
// i.e.:
18+
// 'mouseover' event -> 'mouseover' function
19+
// 'mouseout' event -> 'mouseout' function
20+
// 'click' event -> 'click' function
21+
// Should call function 'update' at least once
2122

22-
describe('placeholder', () => {
23-
xit('placeholder for tests', () => {
24-
expect(1+1).toEqual(2);
25-
})
26-
})
23+
describe('placeholder', () => {
24+
it.skip('placeholder for tests', () => {
25+
expect(1 + 1).toEqual(2);
26+
});
27+
});

0 commit comments

Comments
 (0)