-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappState.js
57 lines (41 loc) · 1.05 KB
/
appState.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import buildGraph from './lib/buildGraph';
import Progress from './Progress';
const queryState = require('query-state');
const qs = queryState(
{
query: ''
},
{
useSearch: true
}
);
let lastBuilder;
const appStateFromQuery = qs.get();
const appState = {
hasGraph: false,
maxDepth: appStateFromQuery.maxDepth || 2,
progress: new Progress(),
graph: null,
query: appStateFromQuery.query
};
if (appState.query) {
performSearch(appState.query);
}
export default appState;
qs.onChange(updateAppState);
function updateAppState(newState) {
appState.query = newState.query;
}
export function performSearch(queryString) {
appState.hasGraph = true;
appState.progress.reset();
qs.set('query', queryString);
if (lastBuilder) {
lastBuilder.dispose();
}
lastBuilder = buildGraph(queryString, appState.maxDepth, appState.progress);
lastBuilder.graph.rootId = queryString;
appState.graph = Object.freeze(lastBuilder.graph);
// console.log(queryString, "lastBuilder.graph", lastBuilder.graph)
return lastBuilder.graph;
}