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 | import { ConsoleLogger as LoggerClass } from './Logger';
|
18 | var logger = new LoggerClass('Amplify');
|
19 | var AmplifyClass = (function () {
|
20 | function AmplifyClass() {
|
21 |
|
22 | this._components = [];
|
23 | this._config = {};
|
24 |
|
25 | this._modules = {};
|
26 |
|
27 |
|
28 | this.Auth = null;
|
29 | this.Analytics = null;
|
30 | this.API = null;
|
31 | this.Credentials = null;
|
32 | this.Storage = null;
|
33 | this.I18n = null;
|
34 | this.Cache = null;
|
35 | this.PubSub = null;
|
36 | this.Interactions = null;
|
37 | this.Pushnotification = null;
|
38 | this.UI = null;
|
39 | this.XR = null;
|
40 | this.Predictions = null;
|
41 | this.DataStore = null;
|
42 | this.Logger = LoggerClass;
|
43 | this.ServiceWorker = null;
|
44 | }
|
45 | AmplifyClass.prototype.register = function (comp) {
|
46 | logger.debug('component registered in amplify', comp);
|
47 | this._components.push(comp);
|
48 | if (typeof comp.getModuleName === 'function') {
|
49 | this._modules[comp.getModuleName()] = comp;
|
50 | this[comp.getModuleName()] = comp;
|
51 | }
|
52 | else {
|
53 | logger.debug('no getModuleName method for component', comp);
|
54 | }
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | comp.configure(this._config);
|
62 | };
|
63 | AmplifyClass.prototype.configure = function (config) {
|
64 | var _this = this;
|
65 | if (!config)
|
66 | return this._config;
|
67 | this._config = Object.assign(this._config, config);
|
68 | logger.debug('amplify config', this._config);
|
69 |
|
70 |
|
71 |
|
72 | Object.entries(this._modules).forEach(function (_a) {
|
73 | var _b = __read(_a, 2), Name = _b[0], comp = _b[1];
|
74 |
|
75 | Object.keys(comp).forEach(function (property) {
|
76 |
|
77 | if (_this._modules[property]) {
|
78 | comp[property] = _this._modules[property];
|
79 | }
|
80 | });
|
81 | });
|
82 | this._components.map(function (comp) {
|
83 | comp.configure(_this._config);
|
84 | });
|
85 | return this._config;
|
86 | };
|
87 | AmplifyClass.prototype.addPluggable = function (pluggable) {
|
88 | if (pluggable &&
|
89 | pluggable['getCategory'] &&
|
90 | typeof pluggable['getCategory'] === 'function') {
|
91 | this._components.map(function (comp) {
|
92 | if (comp['addPluggable'] &&
|
93 | typeof comp['addPluggable'] === 'function') {
|
94 | comp.addPluggable(pluggable);
|
95 | }
|
96 | });
|
97 | }
|
98 | };
|
99 | return AmplifyClass;
|
100 | }());
|
101 | export { AmplifyClass };
|
102 | export var Amplify = new AmplifyClass();
|
103 |
|
104 |
|
105 |
|
106 | export default Amplify;
|
107 |
|
\ | No newline at end of file |