1 | var __read = (this && this.__read) || function (o, n) {
|
2 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
3 | if (!m) return o;
|
4 | var i = m.call(o), r, ar = [], e;
|
5 | try {
|
6 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
7 | }
|
8 | catch (error) { e = { error: error }; }
|
9 | finally {
|
10 | try {
|
11 | if (r && !r.done && (m = i["return"])) m.call(i);
|
12 | }
|
13 | finally { if (e) throw e.error; }
|
14 | }
|
15 | return ar;
|
16 | };
|
17 |
|
18 |
|
19 | import { ConsoleLogger as LoggerClass } from './Logger';
|
20 | var logger = new LoggerClass('Amplify');
|
21 | var AmplifyClass = (function () {
|
22 | function AmplifyClass() {
|
23 |
|
24 | this._components = [];
|
25 | this._config = {};
|
26 |
|
27 | this._modules = {};
|
28 |
|
29 |
|
30 | this.Auth = null;
|
31 | this.Analytics = null;
|
32 | this.API = null;
|
33 | this.Credentials = null;
|
34 | this.Storage = null;
|
35 | this.I18n = null;
|
36 | this.Cache = null;
|
37 | this.PubSub = null;
|
38 | this.Interactions = null;
|
39 | this.Pushnotification = null;
|
40 | this.UI = null;
|
41 | this.XR = null;
|
42 | this.Predictions = null;
|
43 | this.DataStore = null;
|
44 | this.Geo = null;
|
45 | this.Notifications = null;
|
46 | this.Logger = LoggerClass;
|
47 | this.ServiceWorker = null;
|
48 | }
|
49 | AmplifyClass.prototype.register = function (comp) {
|
50 | logger.debug('component registered in amplify', comp);
|
51 | this._components.push(comp);
|
52 | if (typeof comp.getModuleName === 'function') {
|
53 | this._modules[comp.getModuleName()] = comp;
|
54 | this[comp.getModuleName()] = comp;
|
55 | }
|
56 | else {
|
57 | logger.debug('no getModuleName method for component', comp);
|
58 | }
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | comp.configure(this._config);
|
66 | };
|
67 | AmplifyClass.prototype.configure = function (config) {
|
68 | var _this = this;
|
69 | if (!config)
|
70 | return this._config;
|
71 | this._config = Object.assign(this._config, config);
|
72 | logger.debug('amplify config', this._config);
|
73 |
|
74 |
|
75 |
|
76 | Object.entries(this._modules).forEach(function (_a) {
|
77 | var _b = __read(_a, 2), Name = _b[0], comp = _b[1];
|
78 |
|
79 | Object.keys(comp).forEach(function (property) {
|
80 |
|
81 | if (_this._modules[property]) {
|
82 | comp[property] = _this._modules[property];
|
83 | }
|
84 | });
|
85 | });
|
86 | this._components.map(function (comp) {
|
87 | comp.configure(_this._config);
|
88 | });
|
89 | return this._config;
|
90 | };
|
91 | AmplifyClass.prototype.addPluggable = function (pluggable) {
|
92 | if (pluggable &&
|
93 | pluggable['getCategory'] &&
|
94 | typeof pluggable['getCategory'] === 'function') {
|
95 | this._components.map(function (comp) {
|
96 | if (comp['addPluggable'] &&
|
97 | typeof comp['addPluggable'] === 'function') {
|
98 | comp.addPluggable(pluggable);
|
99 | }
|
100 | });
|
101 | }
|
102 | };
|
103 | return AmplifyClass;
|
104 | }());
|
105 | export { AmplifyClass };
|
106 | export var Amplify = new AmplifyClass();
|