UNPKG

16.5 kBJavaScriptView Raw
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('firebase/app'), require('firebase/remote-config'), require('firebase/messaging'), require('firebase/analytics'), require('rxjs'), require('rxjs/operators')) :
3 typeof define === 'function' && define.amd ? define('@angular/fire', ['exports', '@angular/core', 'firebase/app', 'firebase/remote-config', 'firebase/messaging', 'firebase/analytics', 'rxjs', 'rxjs/operators'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.angular = global.angular || {}, global.angular.fire = {}), global.ng, global.firebase, global.remoteConfig, global.messaging, global.analytics, global.rxjs, global.rxjs.operators));
5}(this, (function (exports, i0, app, remoteConfig, messaging, analytics, rxjs, operators) { 'use strict';
6
7 function _interopNamespace(e) {
8 if (e && e.__esModule) return e;
9 var n = Object.create(null);
10 if (e) {
11 Object.keys(e).forEach(function (k) {
12 if (k !== 'default') {
13 var d = Object.getOwnPropertyDescriptor(e, k);
14 Object.defineProperty(n, k, d.get ? d : {
15 enumerable: true,
16 get: function () {
17 return e[k];
18 }
19 });
20 }
21 });
22 }
23 n['default'] = e;
24 return Object.freeze(n);
25 }
26
27 var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
28
29 var VERSION = new i0.Version('7.3.0');
30 var isAnalyticsSupportedValueSymbol = '__angularfire_symbol__analyticsIsSupportedValue';
31 var isAnalyticsSupportedPromiseSymbol = '__angularfire_symbol__analyticsIsSupported';
32 var isRemoteConfigSupportedValueSymbol = '__angularfire_symbol__remoteConfigIsSupportedValue';
33 var isRemoteConfigSupportedPromiseSymbol = '__angularfire_symbol__remoteConfigIsSupported';
34 var isMessagingSupportedValueSymbol = '__angularfire_symbol__messagingIsSupportedValue';
35 var isMessagingSupportedPromiseSymbol = '__angularfire_symbol__messagingIsSupported';
36 globalThis[isAnalyticsSupportedPromiseSymbol] || (globalThis[isAnalyticsSupportedPromiseSymbol] = analytics.isSupported().then(function (it) { return globalThis[isAnalyticsSupportedValueSymbol] = it; }).catch(function () { return globalThis[isAnalyticsSupportedValueSymbol] = false; }));
37 globalThis[isMessagingSupportedPromiseSymbol] || (globalThis[isMessagingSupportedPromiseSymbol] = messaging.isSupported().then(function (it) { return globalThis[isMessagingSupportedValueSymbol] = it; }).catch(function () { return globalThis[isMessagingSupportedValueSymbol] = false; }));
38 globalThis[isRemoteConfigSupportedPromiseSymbol] || (globalThis[isRemoteConfigSupportedPromiseSymbol] = remoteConfig.isSupported().then(function (it) { return globalThis[isRemoteConfigSupportedValueSymbol] = it; }).catch(function () { return globalThis[isRemoteConfigSupportedValueSymbol] = false; }));
39 var isSupportedError = function (module) { return "The APP_INITIALIZER that is \"making\" isSupported() sync for the sake of convenient DI has not resolved in this\ncontext. Rather than injecting " + module + " in the constructor, first ensure that " + module + " is supported by calling\n`await isSupported()`, then retrieve the instance from the injector manually `injector.get(" + module + ")`."; };
40 var ɵisMessagingSupportedFactory = {
41 async: function () { return globalThis[isMessagingSupportedPromiseSymbol]; },
42 sync: function () {
43 var ret = globalThis[isMessagingSupportedValueSymbol];
44 if (ret === undefined) {
45 throw new Error(isSupportedError('Messaging'));
46 }
47 return ret;
48 }
49 };
50 var ɵisRemoteConfigSupportedFactory = {
51 async: function () { return globalThis[isRemoteConfigSupportedPromiseSymbol]; },
52 sync: function () {
53 var ret = globalThis[isRemoteConfigSupportedValueSymbol];
54 if (ret === undefined) {
55 throw new Error(isSupportedError('RemoteConfig'));
56 }
57 return ret;
58 }
59 };
60 var ɵisAnalyticsSupportedFactory = {
61 async: function () { return globalThis[isAnalyticsSupportedPromiseSymbol]; },
62 sync: function () {
63 var ret = globalThis[isAnalyticsSupportedValueSymbol];
64 if (ret === undefined) {
65 throw new Error(isSupportedError('Analytics'));
66 }
67 return ret;
68 }
69 };
70 function ɵgetDefaultInstanceOf(identifier, provided, defaultApp) {
71 if (provided) {
72 // Was provide* only called once? If so grab that
73 if (provided.length === 1) {
74 return provided[0];
75 }
76 var providedUsingDefaultApp = provided.filter(function (it) { return it.app === defaultApp; });
77 // Was provide* only called once, using the default app? If so use that
78 if (providedUsingDefaultApp.length === 1) {
79 return providedUsingDefaultApp[0];
80 }
81 }
82 // Grab the default instance from the defaultApp
83 var defaultAppWithContainer = defaultApp;
84 var provider = defaultAppWithContainer.container.getProvider(identifier);
85 return provider.getImmediate({ optional: true });
86 }
87 var ɵgetAllInstancesOf = function (identifier, app$1) {
88 var apps = app$1 ? [app$1] : app.getApps();
89 var instances = [];
90 apps.forEach(function (app) {
91 var provider = app.container.getProvider(identifier);
92 provider.instances.forEach(function (instance) {
93 if (!instances.includes(instance)) {
94 instances.push(instance);
95 }
96 });
97 });
98 return instances;
99 };
100
101 var _this_1 = this;
102 function noop() {
103 }
104 /**
105 * Schedules tasks so that they are invoked inside the Zone that is passed in the constructor.
106 */
107 // tslint:disable-next-line:class-name
108 var ɵZoneScheduler = /** @class */ (function () {
109 function ɵZoneScheduler(zone, delegate) {
110 if (delegate === void 0) { delegate = rxjs.queueScheduler; }
111 this.zone = zone;
112 this.delegate = delegate;
113 }
114 ɵZoneScheduler.prototype.now = function () {
115 return this.delegate.now();
116 };
117 ɵZoneScheduler.prototype.schedule = function (work, delay, state) {
118 var targetZone = this.zone;
119 // Wrap the specified work function to make sure that if nested scheduling takes place the
120 // work is executed in the correct zone
121 var workInZone = function (state) {
122 var _this_1 = this;
123 targetZone.runGuarded(function () {
124 work.apply(_this_1, [state]);
125 });
126 };
127 // Scheduling itself needs to be run in zone to ensure setInterval calls for async scheduling are done
128 // inside the correct zone. This scheduler needs to schedule asynchronously always to ensure that
129 // firebase emissions are never synchronous. Specifying a delay causes issues with the queueScheduler delegate.
130 return this.delegate.schedule(workInZone, delay, state);
131 };
132 return ɵZoneScheduler;
133 }());
134 var BlockUntilFirstOperator = /** @class */ (function () {
135 function BlockUntilFirstOperator(zone) {
136 this.zone = zone;
137 this.task = null;
138 }
139 BlockUntilFirstOperator.prototype.call = function (subscriber, source) {
140 var unscheduleTask = this.unscheduleTask.bind(this);
141 this.task = this.zone.run(function () { return Zone.current.scheduleMacroTask('firebaseZoneBlock', noop, {}, noop, noop); });
142 return source.pipe(operators.tap({ next: unscheduleTask, complete: unscheduleTask, error: unscheduleTask })).subscribe(subscriber).add(unscheduleTask);
143 };
144 BlockUntilFirstOperator.prototype.unscheduleTask = function () {
145 var _this_1 = this;
146 // maybe this is a race condition, invoke in a timeout
147 // hold for 10ms while I try to figure out what is going on
148 setTimeout(function () {
149 if (_this_1.task != null && _this_1.task.state === 'scheduled') {
150 _this_1.task.invoke();
151 _this_1.task = null;
152 }
153 }, 10);
154 };
155 return BlockUntilFirstOperator;
156 }());
157 // tslint:disable-next-line:class-name
158 var ɵAngularFireSchedulers = /** @class */ (function () {
159 function ɵAngularFireSchedulers(ngZone) {
160 this.ngZone = ngZone;
161 this.outsideAngular = ngZone.runOutsideAngular(function () { return new ɵZoneScheduler(Zone.current); });
162 this.insideAngular = ngZone.run(function () { return new ɵZoneScheduler(Zone.current, rxjs.asyncScheduler); });
163 globalThis.ɵAngularFireScheduler || (globalThis.ɵAngularFireScheduler = this);
164 }
165 return ɵAngularFireSchedulers;
166 }());
167 ɵAngularFireSchedulers.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: ɵAngularFireSchedulers, deps: [{ token: i0__namespace.NgZone }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
168 ɵAngularFireSchedulers.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: ɵAngularFireSchedulers, providedIn: 'root' });
169 i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0__namespace, type: ɵAngularFireSchedulers, decorators: [{
170 type: i0.Injectable,
171 args: [{
172 providedIn: 'root',
173 }]
174 }], ctorParameters: function () { return [{ type: i0__namespace.NgZone }]; } });
175 function getSchedulers() {
176 var schedulers = globalThis.ɵAngularFireScheduler;
177 if (!schedulers) {
178 throw new Error("Either AngularFireModule has not been provided in your AppModule (this can be done manually or implictly using\nprovideFirebaseApp) or you're calling an AngularFire method outside of an NgModule (which is not supported).");
179 }
180 return schedulers;
181 }
182 function runOutsideAngular(fn) {
183 return getSchedulers().ngZone.runOutsideAngular(function () { return fn(); });
184 }
185 function run(fn) {
186 return getSchedulers().ngZone.run(function () { return fn(); });
187 }
188 function observeOutsideAngular(obs$) {
189 return obs$.pipe(operators.observeOn(getSchedulers().outsideAngular));
190 }
191 function observeInsideAngular(obs$) {
192 return obs$.pipe(operators.observeOn(getSchedulers().insideAngular));
193 }
194 function keepUnstableUntilFirst(obs$) {
195 var scheduler = getSchedulers();
196 return ɵkeepUnstableUntilFirstFactory(getSchedulers())(obs$);
197 }
198 /**
199 * Operator to block the zone until the first value has been emitted or the observable
200 * has completed/errored. This is used to make sure that universal waits until the first
201 * value from firebase but doesn't block the zone forever since the firebase subscription
202 * is still alive.
203 */
204 function ɵkeepUnstableUntilFirstFactory(schedulers) {
205 return function keepUnstableUntilFirst(obs$) {
206 obs$ = obs$.lift(new BlockUntilFirstOperator(schedulers.ngZone));
207 return obs$.pipe(
208 // Run the subscribe body outside of Angular (e.g. calling Firebase SDK to add a listener to a change event)
209 operators.subscribeOn(schedulers.outsideAngular),
210 // Run operators inside the angular zone (e.g. side effects via tap())
211 operators.observeOn(schedulers.insideAngular)
212 // INVESTIGATE https://github.com/angular/angularfire/pull/2315
213 // share()
214 );
215 };
216 }
217 var zoneWrapFn = function (it, macrotask) {
218 var _this = _this_1;
219 // function() is needed for the arguments object
220 // tslint:disable-next-line:only-arrow-functions
221 return function () {
222 var _arguments = arguments;
223 if (macrotask) {
224 setTimeout(function () {
225 if (macrotask.state === 'scheduled') {
226 macrotask.invoke();
227 }
228 }, 10);
229 }
230 return run(function () { return it.apply(_this, _arguments); });
231 };
232 };
233 var ɵzoneWrap = function (it, blockUntilFirst) {
234 // function() is needed for the arguments object
235 // tslint:disable-next-line:only-arrow-functions
236 return function () {
237 var _this_1 = this;
238 var macrotask;
239 var _arguments = arguments;
240 // if this is a callback function, e.g, onSnapshot, we should create a microtask and invoke it
241 // only once one of the callback functions is tripped.
242 for (var i = 0; i < arguments.length; i++) {
243 if (typeof _arguments[i] === 'function') {
244 if (blockUntilFirst) {
245 macrotask || (macrotask = run(function () { return Zone.current.scheduleMacroTask('firebaseZoneBlock', noop, {}, noop, noop); }));
246 }
247 // TODO create a microtask to track callback functions
248 _arguments[i] = zoneWrapFn(_arguments[i], macrotask);
249 }
250 }
251 var ret = runOutsideAngular(function () { return it.apply(_this_1, _arguments); });
252 if (!blockUntilFirst) {
253 if (ret instanceof rxjs.Observable) {
254 var schedulers = getSchedulers();
255 return ret.pipe(operators.subscribeOn(schedulers.outsideAngular), operators.observeOn(schedulers.insideAngular));
256 }
257 else {
258 return run(function () { return ret; });
259 }
260 }
261 if (ret instanceof rxjs.Observable) {
262 return ret.pipe(keepUnstableUntilFirst);
263 }
264 else if (ret instanceof Promise) {
265 return run(function () { return new Promise(function (resolve, reject) { return ret.then(function (it) { return run(function () { return resolve(it); }); }, function (reason) { return run(function () { return reject(reason); }); }); }); });
266 }
267 else if (typeof ret === 'function' && macrotask) {
268 // Handle unsubscribe
269 // function() is needed for the arguments object
270 // tslint:disable-next-line:only-arrow-functions
271 return function () {
272 setTimeout(function () {
273 if (macrotask && macrotask.state === 'scheduled') {
274 macrotask.invoke();
275 }
276 }, 10);
277 return ret.apply(this, arguments);
278 };
279 }
280 else {
281 // TODO how do we handle storage uploads in Zone? and other stuff with cancel() etc?
282 return run(function () { return ret; });
283 }
284 };
285 };
286
287 /**
288 * Generated bundle index. Do not edit.
289 */
290
291 exports.VERSION = VERSION;
292 exports.keepUnstableUntilFirst = keepUnstableUntilFirst;
293 exports.observeInsideAngular = observeInsideAngular;
294 exports.observeOutsideAngular = observeOutsideAngular;
295 exports.ɵAngularFireSchedulers = ɵAngularFireSchedulers;
296 exports.ɵZoneScheduler = ɵZoneScheduler;
297 exports.ɵgetAllInstancesOf = ɵgetAllInstancesOf;
298 exports.ɵgetDefaultInstanceOf = ɵgetDefaultInstanceOf;
299 exports.ɵisAnalyticsSupportedFactory = ɵisAnalyticsSupportedFactory;
300 exports.ɵisMessagingSupportedFactory = ɵisMessagingSupportedFactory;
301 exports.ɵisRemoteConfigSupportedFactory = ɵisRemoteConfigSupportedFactory;
302 exports.ɵkeepUnstableUntilFirstFactory = ɵkeepUnstableUntilFirstFactory;
303 exports.ɵzoneWrap = ɵzoneWrap;
304
305 Object.defineProperty(exports, '__esModule', { value: true });
306
307})));
308//# sourceMappingURL=angular-fire.umd.js.map