1 | import { syncHistoryWithStore } from 'react-router-redux'
|
2 | import * as portionConfig from '__KOOT_PROJECT_CONFIG_PORTION_CLIENT_PATHNAME__'
|
3 | import validateReduxConfig from './validate/redux-config'
|
4 | import History from './history'
|
5 |
|
6 | window.__KOOT_STORE__ = ((reduxConfig = {}) => {
|
7 | if (typeof reduxConfig.factoryStore === 'function')
|
8 | return reduxConfig.factoryStore()
|
9 | if (typeof reduxConfig.store === 'object')
|
10 | return reduxConfig.store
|
11 | return {}
|
12 | })(validateReduxConfig(portionConfig.redux))
|
13 |
|
14 | window.__KOOT_HISTORY__ = syncHistoryWithStore(History, window.__KOOT_STORE__)
|
15 |
|
16 | // console filter
|
17 | // https://stackoverflow.com/questions/6659312/is-there-a-way-to-filter-output-in-google-chromes-console
|
18 | /*
|
19 | if (__DEV__) {
|
20 | (() => {
|
21 | window.console = window.console || { log: 0 }
|
22 |
|
23 | const nativeConsole = {
|
24 | log: window.console.log,
|
25 | info: window.console.info,
|
26 | error: window.console.error,
|
27 | }
|
28 |
|
29 | const lastLog = {
|
30 | WDS: {
|
31 | time: undefined,
|
32 | log: undefined,
|
33 | },
|
34 | HMR: {
|
35 | time: undefined,
|
36 | log: undefined,
|
37 | },
|
38 | };
|
39 | const throttleHotLog = (level) => {
|
40 | window.console[level] = function () {
|
41 | try {
|
42 | const args = Array.from(arguments)
|
43 |
|
44 | // throttle `WDS` and `HMR` logs
|
45 | const needThrottle = (type) => {
|
46 | const regex = new RegExp(`^\\[${type}\\]`)
|
47 | if (!args.some(arg => regex.test(arg))) return false
|
48 |
|
49 | const { [type]: last } = lastLog
|
50 | const now = Date.now()
|
51 | const nowLogStr = args.join('|||')
|
52 | const {
|
53 | time: lastTime,
|
54 | log: lastLogStr
|
55 | } = last
|
56 | lastLog[type] = {
|
57 | time: now,
|
58 | log: nowLogStr
|
59 | }
|
60 | // console.warn(type, last, now - lastTime)
|
61 |
|
62 | if (
|
63 | lastTime &&
|
64 | now - lastTime < 50 &&
|
65 | lastLogStr &&
|
66 | lastLogStr === nowLogStr
|
67 | ) return true
|
68 | return false
|
69 | }
|
70 | if (needThrottle('WDS')) return
|
71 | if (needThrottle('HMR')) return
|
72 |
|
73 | nativeConsole[level].apply(window.console, arguments)
|
74 |
|
75 | } catch (e) { }
|
76 | }
|
77 | }
|
78 | // throttleHotLog('log')
|
79 | throttleHotLog('info')
|
80 |
|
81 | const warnings = {
|
82 | reactRouterV3: false,
|
83 | reactReduxV5: false,
|
84 | }
|
85 | window.console.error = function () {
|
86 | try {
|
87 | const args = Array.from(arguments)
|
88 |
|
89 | // filter out `react-redux v5` & `react-router v3` warnings/erros
|
90 | if (
|
91 | (
|
92 | args.some(arg => /^Warning: Legacy context API has been detected within a strict-mode tree/.test(arg))
|
93 | && args.some(arg => arg === 'Link')
|
94 | )
|
95 | ||
|
96 | (
|
97 | args.some(arg => /^Warning: Unsafe lifecycle methods were found within a strict-mode tree/.test(arg))
|
98 | && args.some(arg => /^componentWillReceiveProps: Please update the following components to use static getDerivedStateFromProps instead: Link$/.test(arg))
|
99 | )
|
100 | ) {
|
101 | if (!warnings.reactRouterV3) {
|
102 | console.warn('[koot] Koot.js is now using `react-router` v3 which will be upgraded to new version in future.')
|
103 | warnings.reactRouterV3 = true
|
104 | }
|
105 | return
|
106 | }
|
107 |
|
108 | nativeConsole.error.apply(window.console, arguments)
|
109 |
|
110 | } catch (e) { }
|
111 | }
|
112 | })()
|
113 |
|
114 | }
|
115 | */
|