-
Notifications
You must be signed in to change notification settings - Fork 30
/
normalize.js
52 lines (41 loc) · 1.06 KB
/
normalize.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
import React from 'react'
import { Provider } from 'react-redux'
import { clone } from '../helpers'
// Normalizes common settings
export default function normalizeSettings(settings)
{
if (settings === undefined) {
throw new Error(`Common settings weren't passed.`)
}
if (typeof settings !== 'object') {
throw new Error(`Expected a settings object, got ${typeof settings}: ${settings}`)
}
settings = clone(settings)
if (!settings.routes) {
throw new Error(`"routes" parameter is required`)
}
if (!settings.reducers) {
throw new Error(`"reducers" parameter is required`)
}
if (!settings.container) {
// By default it wraps everything with Redux `<Provider/>`.
settings.container = function Container({ store, children }) {
return (
<Provider store={ store }>
{ children }
</Provider>
)
}
}
// Default value for `parseDates` is `true`
if (settings.parseDates !== false) {
settings.parseDates = true
}
if (!settings.http) {
settings.http = {}
}
if (!settings.authentication) {
settings.authentication = {}
}
return settings
}