-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathiooxa.ts
49 lines (43 loc) · 1.35 KB
/
iooxa.ts
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
import { applyMiddleware, createStore, combineReducers } from 'redux';
import thunkMiddleware from 'redux-thunk';
import runtime, {
types, setup, actions, selectors,
} from '@iooxa/runtime';
import { register as basicRegister } from '@iooxa/components';
import { register as chartRegister } from '@iooxa/svg';
import * as components from './src/components';
import setupArticle from './src/components/article';
interface Iooxa {
store: types.Store;
getVariableByName: (name: string) => types.VariableShortcut | null;
createVariable: (...args: Parameters<typeof actions.createVariable>) => types.VariableShortcut;
}
declare global {
interface Window {
iooxa: Iooxa;
}
}
const store = createStore(
combineReducers({ runtime: runtime.reducer }),
applyMiddleware(
thunkMiddleware,
runtime.triggerEvaluate,
runtime.dangerousEvaluatation,
),
) as types.Store;
function getVariableByName(name: string) {
const variable = selectors.getVariableByName(store.getState(), name);
if (variable == null) return null;
return actions.variableShortcut(store.dispatch, store.getState, variable.id);
}
window.iooxa = {
...window.iooxa,
store,
getVariableByName,
createVariable: (...args) => store.dispatch(actions.createVariable(...args)),
} as Iooxa;
setup(window.iooxa.store);
basicRegister();
chartRegister();
components.register();
setupArticle();