1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.initModules = undefined;
|
7 |
|
8 | var _typeof2 = require('babel-runtime/helpers/typeof');
|
9 |
|
10 | var _typeof3 = _interopRequireDefault(_typeof2);
|
11 |
|
12 | var _appContext = require('./appContext');
|
13 |
|
14 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | var sanityCheckModules = function sanityCheckModules(modules) {
|
29 | modules.forEach(function (m, i) {
|
30 | if (typeof m !== 'function') {
|
31 | throw new Error('initModules() module index ' + i + ' (' + modules.length + ' total) is ' + (typeof m === 'undefined' ? 'undefined' : (0, _typeof3.default)(m)) + ', not a function');
|
32 | }
|
33 | });
|
34 | };
|
35 |
|
36 | var sanityCheckDuplicateContextName = function sanityCheckDuplicateContextName(newNames) {
|
37 | var existingContextNames = new Set(Object.keys(_appContext.appContext));
|
38 | newNames.forEach(function (newName) {
|
39 | if (existingContextNames.has(newName)) {
|
40 | throw new ReferenceError('initModules() with more than one context member called "' + newName + '"');
|
41 | }
|
42 | });
|
43 | };
|
44 |
|
45 | var initModules = exports.initModules = function initModules(modules) {
|
46 | sanityCheckModules(modules);
|
47 | modules.forEach(function (module) {
|
48 | var context = module(_appContext.appContext);
|
49 | if (context) {
|
50 | sanityCheckDuplicateContextName(Object.keys(context));
|
51 | Object.assign(_appContext.appContext, context);
|
52 | }
|
53 | });
|
54 | }; |
\ | No newline at end of file |