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