-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
75 lines (69 loc) · 1.92 KB
/
index.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
import { react, html } from '../utils/rplus.js';
import { StateProvider } from './utils/globalState.js';
import { parseUrl } from './utils/parseUrl.js';
import Main from './components/Main.js';
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('./sw.js')
.then(() => console.log('[runpkg] service worker registered'))
.catch(err => console.log(err));
}
const initialState = {
packages: [],
packagesSearchTerm: '',
fileSearchTerm: '',
noUrlPackageFound: '',
dependencySearchTerm: '',
request: parseUrl(),
directory: {},
versions: {},
cache: {},
mode: 'registry',
};
function reducer(state, action) {
switch (action.type) {
case 'setMode':
return { ...state, mode: action.payload };
case 'setPackages':
return { ...state, packages: action.payload };
case 'setPackagesSearchTerm':
return { ...state, packagesSearchTerm: action.payload };
case 'setFileSearchTerm':
return { ...state, fileSearchTerm: action.payload };
case 'setDependencySearchTerm':
return { ...state, dependencySearchTerm: action.payload };
case 'setRequest':
return {
...state,
noUrlPackageFound: '',
request: action.payload,
mode: !action.payload.name ? 'registry' : state.mode,
};
case 'setNoURLPackageFound':
return { ...state, noUrlPackageFound: action.payload };
case 'setDirectory':
return { ...state, directory: action.payload };
case 'setFile':
return { ...state, file: action.payload };
case 'setVersions':
return { ...state, versions: action.payload };
case 'setCache':
return {
...state,
cache: { ...state.cache, ...action.payload },
};
default:
return { ...state };
}
}
const App = () => html`
<${StateProvider} initialState=${initialState} reducer=${reducer}>
<${Main} />
<//>
`;
react.render(
html`
<${App} />
`,
document.body
);