Skip to content

Commit 1dac9c7

Browse files
authored
Merge pull request #278 from open-source-labs/dev
🚨 Release v0.5.0
2 parents 367d6df + 4f79671 commit 1dac9c7

File tree

97 files changed

+24990
-12296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+24990
-12296
lines changed

.babelrc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
},
77
"presets": [
88
"@babel/preset-env",
9-
"@babel/preset-react"
9+
"@babel/preset-react",
10+
"@babel/preset-typescript"
1011
],
1112
"plugins": [
12-
["@babel/transform-runtime"]
13-
],
13+
["@babel/transform-runtime"],
14+
["@babel/proposal-class-properties"],
15+
["@babel/proposal-object-rest-spread"]
16+
]
1417
}

.eslintrc.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,102 @@
4343
// }]
4444
// }
4545
// };
46+
47+
module.exports = {
48+
env: {
49+
es6: true,
50+
jest: true,
51+
node: true,
52+
},
53+
extends: [
54+
"airbnb",
55+
"prettier",
56+
"prettier/@typescript-eslint",
57+
"prettier/react",
58+
// "plugin:@typescript-eslint/eslint-recommended",
59+
// "plugin:@typescript-eslint/recommended",
60+
],
61+
globals: {
62+
Atomics: "readonly",
63+
SharedArrayBuffer: "readonly",
64+
},
65+
parser: "babel-eslint",
66+
// parser: "@typescript-eslint/parser",
67+
parserOptions: {
68+
ecmaVersion: 2020,
69+
ecmaFeatures: {
70+
jsx: true,
71+
classes: true,
72+
},
73+
},
74+
plugins: [
75+
// "@typescript-eslint",
76+
"react",
77+
"jsx-a11y",
78+
"import",
79+
"jest",
80+
"react-hooks",
81+
],
82+
rules: {
83+
"arrow-body-style": 0,
84+
camelcase: 0,
85+
"class-methods-use-this": 0,
86+
"consistent-return": 0,
87+
"comma-dangle": 0,
88+
"dot-notation": 0,
89+
"func-names": 0,
90+
"guard-for-in": 0,
91+
"import/extensions": 0,
92+
"import/no-extraneous-dependencies": 0,
93+
"import/no-unresolved": 0,
94+
"import/prefer-default-export": 0,
95+
"max-len": 0,
96+
"no-alert": 0,
97+
"no-console": 0,
98+
"no-param-reassign": 0,
99+
"no-plusplus": 0,
100+
"no-restricted-globals": 1,
101+
"no-restricted-syntax": 0,
102+
"no-shadow": 0,
103+
"no-undef": 0,
104+
"no-unused-vars": 0,
105+
"no-use-before-define": 0,
106+
"no-useless-constructor": 0,
107+
"no-underscore-dangle": 0,
108+
"no-unused-expressions": 0,
109+
"no-return-assign": 0,
110+
quotes: 0,
111+
"prefer-const": 1,
112+
"prefer-destructuring": 0,
113+
"prefer-template": 0,
114+
"react/button-has-type": 0,
115+
"react/destructuring-assignment": 0,
116+
"react/forbid-prop-types": 0,
117+
"react/jsx-filename-extension": 0,
118+
"react/jsx-no-duplicate-props": 0,
119+
"react/no-access-state-in-setstate": 0,
120+
"react/no-array-index-key": 0,
121+
"react/no-did-update-set-state": 0,
122+
"react/no-unused-state": 0,
123+
"react/prefer-stateless-function": 0,
124+
"react/sort-comp": [
125+
2,
126+
{
127+
order: ["lifecycle", "everything-else", "rendering"],
128+
},
129+
],
130+
"react/prop-types": 0,
131+
"spaced-comment": 0,
132+
strict: 0,
133+
},
134+
// setting: {
135+
// "import/parsers": {
136+
// "@typescript-eslint/parser": [".ts", ".tsx"],
137+
// },
138+
// "import/resolver": {
139+
// typescript: {
140+
// alwaysTryTypes: true,
141+
// },
142+
// },
143+
// },
144+
};

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ ehthumbs.db
5959
# proto files #
6060
#####################
6161
protos/
62+
63+
# testing #
64+
test/snapshot.png

SSEController.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const http = require('http');
2+
// native browser api that we are bringing in to work in a node environmnet
3+
const EventSource = require('eventsource');
4+
5+
const SSEController = {};
6+
7+
// keep reference to what will be our EventSource that listens for SSE's
8+
let sse;
9+
10+
SSEController.createStream = (reqResObj, options, event) => {
11+
// got options from httpController
12+
const { headers } = options;
13+
// because EventSource cannot access headers, we are making a regular get request to SSE server to get its headers, and then passing those headers into function where we will be connecting our EventSource, there will a time delay between the time the user opens the request and the server sends back its first response. We keep reference to the time the first request was made to account for that time difference later on.
14+
const startTime = Date.now();
15+
16+
const req = http.get(headers.url, {
17+
headers,
18+
agent: false,
19+
});
20+
req.once('response', (res) => {
21+
// update info in reqResObj to reflect fact that connection was succesful
22+
reqResObj.response.headers = {...res.headers};
23+
reqResObj.connection = 'open';
24+
reqResObj.connectionType = 'SSE';
25+
// this is for purpose of logic in graph.jsx, which needs the entire req/res obj to have a timeReceived
26+
reqResObj.timeReceived = Date.now();
27+
// invoke function that will create an EventSource
28+
SSEController.readStream(reqResObj, event, Date.now() - startTime);
29+
req.destroy();
30+
});
31+
};
32+
33+
SSEController.readStream = (reqResObj, event, timeDiff) => {
34+
// EventSource listens for SSE's and process specially formatted data from them, as well as adding other useful information
35+
sse = new EventSource(reqResObj.url);
36+
// event listeners
37+
sse.onopen = () => console.log(`SSE at ${reqResObj.url} opened!`);
38+
// this is where incoming messages are processed
39+
sse.onmessage = (message) => {
40+
// message is not a javascript object, so we spread its contents into one
41+
const newMessage = { ...message };
42+
// this is where where account for any time lost between the first AJAX request and the creation of the EventSource
43+
newMessage.timeReceived = Date.now() - timeDiff;
44+
// add processed message to events array on reqResObj
45+
reqResObj.response.events.push(newMessage);
46+
// ...and send back to renderer process to be added to the store
47+
return event.sender.send('reqResUpdate', reqResObj);
48+
};
49+
sse.onerror = (err) => {
50+
console.log('there was an error in SSEController.readStream', err);
51+
sse.close();
52+
};
53+
};
54+
55+
module.exports = SSEController;

__mocks__/electronMock.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export const ipcRenderer = {
2-
on: jest.fn()
3-
};
1+
export const ipcRenderer = {
2+
on: jest.fn(),
3+
};

__mocks__/fileMock.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// see jest.config
2+
module.exports = "test-file-stub";

__mocks__/styleMocks.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
module.exports = 'test-file-stub';
1+
// see jest.config
2+
3+
module.exports = {};

0 commit comments

Comments
 (0)