-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
35 lines (30 loc) · 801 Bytes
/
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
// Helper functions and prop passing system
const state = {};
const listeners = {};
function useState(key, initialValue) {
if (!(key in state)) {
state[key] = initialValue;
}
const setValue = (newValue) => {
state[key] = newValue;
if (listeners[key]) {
listeners[key].forEach(callback => callback(newValue));
}
};
return [state[key], setValue];
}
function useEffect(callback, dependencies) {
dependencies.forEach(dep => {
if (!listeners[dep]) {
listeners[dep] = [];
}
listeners[dep].push(callback);
});
}
// Initialize widgets
document.querySelectorAll('.widget').forEach(widget => {
const route = widget.dataset.route;
if (window[`init${route.replace(/\//g, '_')}`]) {
window[`init${route.replace(/\//g, '_')}`](widget);
}
});