UNPKG

2.03 kBJavaScriptView Raw
1/* global
2 __KOOT_STORE__:false,
3 __KOOT_HISTORY__:false,
4 __KOOT_LOCALEID__:false,
5*/
6
7/**
8 * 手动创建 Redux Store 时需要的相关对象
9 * @type {Object}
10 */
11import * as reduxForCreateStore from './React/redux';
12
13export { reduxForCreateStore };
14
15/**
16 * 通用的高阶组件/方法的装饰器
17 * @type {Function}
18 */
19export { default as extend } from '__KOOT_HOC_EXTEND__';
20
21// 其他全局变量
22export const getLocaleId = () => {
23 if (__CLIENT__) return window.__KOOT_LOCALEID__ || '';
24 if (__SERVER__) {
25 if (__DEV__) return global.__KOOT_LOCALEID__;
26 if (typeof __KOOT_LOCALEID__ === 'undefined') return '';
27 return __KOOT_LOCALEID__ || '';
28 }
29};
30export const resetLocaleId = () => (localeId = getLocaleId());
31export let localeId = (() => getLocaleId())();
32
33export const getStore = () => {
34 if (__CLIENT__) return window.__KOOT_STORE__;
35 if (__SERVER__) {
36 if (__DEV__) return global.__KOOT_STORE__;
37 if (typeof __KOOT_STORE__ === 'undefined') return '';
38 return __KOOT_STORE__;
39 }
40};
41export const resetStore = () => (store = getStore());
42export let store = (() => getStore())();
43
44export const getHistory = () => {
45 if (__CLIENT__) return window.__KOOT_HISTORY__;
46 if (__SERVER__) {
47 if (__DEV__) return global.__KOOT_HISTORY__;
48 if (typeof __KOOT_HISTORY__ === 'undefined') return '';
49 return __KOOT_HISTORY__;
50 }
51};
52export const resetHistory = () => (history = getHistory());
53export let history = (() => getHistory())();
54
55if (__DEV__) {
56 global.__KOOT_SSR_SET__ = v => {
57 global.__KOOT_SSR__ = v;
58 };
59 global.__KOOT_SSR_SET_LOCALEID__ = v => {
60 global.__KOOT_LOCALEID__ = v;
61 localeId = v;
62 };
63 global.__KOOT_SSR_SET_STORE__ = v => {
64 global.__KOOT_STORE__ = v;
65 store = v;
66 };
67 global.__KOOT_SSR_SET_HISTORY__ = v => {
68 global.__KOOT_HISTORY__ = v;
69 history = v;
70 };
71}