-
Notifications
You must be signed in to change notification settings - Fork 27
/
appState.js
81 lines (73 loc) · 2.28 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import queryState from 'query-state';
import LanguageCollection from './LanguageCollection';
import createSideBarState from './createSideBarState.js';
import bus from './bus.js';
import formatNumber from '../utils/formatNumber.js';
const qs = queryState.instance({
lang: 'js',
});
const languages = new LanguageCollection();
languages.add('js', 'JavaScript');
languages.add('jsx', 'React');
languages.add('css', 'Cascading Style Sheets');
languages.add('html', 'HTML');
languages.add('java', 'Java');
languages.add('py', 'Python');
languages.add('lua', 'Lua');
languages.add('php', 'PHP');
languages.add('rb', 'Ruby');
languages.add('cpp', 'C++', '.C, .cc, .cpp, .c++, .cp, .cxx, .h');
languages.add('pl', 'Perl', '.pm');
languages.add('cs', 'C#');
languages.add('scala', 'Scala');
languages.add('go', 'Go');
languages.add('sql', 'SQL');
languages.add('rs', 'Rust');
languages.add('lisp', 'Lisp', '.lsp, .lisp');
languages.add('clj', 'Clojure', '.clj, .cljs');
languages.add('kt', 'Kotlin', '.kt, .ktm, .kts');
languages.add('cmake', 'CMake', '.cmake, .cmake.in');
languages.add('swift', 'Swift');
languages.add('hs', 'Haskell', '.hs, .hsc');
languages.add('ex', 'Elixir', '.ex, .exs');
languages.add('objc', 'Objective C/C++', '.m, .mm');
languages.add('fs', 'F#', '.fs, .fsi');
languages.add('elm', 'Elm', '.elm');
languages.add('purs', 'PureScript', '.purs');
languages.add('pas', 'Pascal', '.pas');
languages.add('r', 'R', '.R');
languages.add('erl', 'Erlang', '.erl');
languages.add('vim', 'VimL', '.vim');
languages.add('groovy', 'Groovy', '.groovy');
languages.select(qs.get('lang'));
qs.onChange(() => {
languages.select(qs.get('lang'));
});
function updateSelected(newLanguage) {
appState.sideBar.close();
languages.select(newLanguage);
qs.set('lang', languages.selected);
}
function selectWord(word) {
appState.sideBar.showContext(word);
}
const appState = {
languages,
listState: {
expanded: false,
},
allWords: [],
sideBar: createSideBarState(languages),
updateSelected,
selectWord,
};
export default appState;
bus.on('context-changed', (context) => {
appState.allWords = Object.keys(context).map(key => context[key])
.sort((x, y) => y.total - x.total)
.map((value, idx) => ({
place: idx,
text: value.word,
total: formatNumber(value.total)
}));
});