UNPKG

@angular/fire

Version:

The official library for Firebase and Angular

16 lines (14 loc) 7.54 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("rxjs"),require("rxjs/operators"),require("@angular/fire"),require("@angular/common")):"function"==typeof define&&define.amd?define("@angular/fire/remote-config",["exports","@angular/core","rxjs","rxjs/operators","@angular/fire","@angular/common"],t):t(((e=e||self).angular=e.angular||{},e.angular.fire=e.angular.fire||{},e.angular.fire["remote-config"]={}),e.ng.core,e.rxjs,e.rxjs.operators,e.angular.fire,e.ng.common)}(this,(function(e,t,n,r,i,o){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var u=function(e,t){return(u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};Object.create;function a(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),u=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)u.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return u}function c(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(a(arguments[t]));return e}Object.create;var s=new t.InjectionToken("angularfire2.remoteConfig.settings"),f=new t.InjectionToken("angularfire2.remoteConfig.defaultConfig"),p={strings:"asString",numbers:"asNumber",booleans:"asBoolean"},l={numbers:0,booleans:!1,strings:void 0},g=function(e,t){return new Proxy(e.pipe(O(t)),{get:function(n,i){return n[i]||e.pipe(r.map((function(e){return e.find((function(e){return e.key===i}))})),r.map((function(e){return e?e[p[t]]():l[t]})),r.distinctUntilChanged())}})},y=function(){function e(e,t){this._source=e,this._value=t}return e.prototype.asBoolean=function(){return["1","true","t","y","yes","on"].indexOf(this._value.toLowerCase())>-1},e.prototype.asString=function(){return this._value},e.prototype.asNumber=function(){return Number(this._value)||0},e.prototype.getSource=function(){return this._source},e}();var d=function(e){function t(t,n,r,i){var o=e.call(this,r,i)||this;return o.key=t,o.fetchTimeMillis=n,o}return function(e,t){function n(){this.constructor=e}u(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}(t,e),t}(y);var m=function(e){return r.filter((function(t){return Array.isArray(t)?t.some(e):e(t)}))},b=function(e){return n.pipe(r.withLatestFrom(e),r.scan((function(e,t){var n=a(t,2),r=n[0],i=n[1];return c(e.map((function(e){return e.key})),Object.keys(r)).filter((function(e,t,n){return n.indexOf(e)===t})).map((function(t){var n=r[t];return n?new d(t,i?i.fetchTimeMillis:-1,n.getSource(),n.asString()):e.find((function(e){return e.key===t}))}))}),[]))},h=function(e,t,u,a,s,f){this.zone=s;var p=new i.ɵAngularFireSchedulers(s),l=n.of(void 0).pipe(r.observeOn(p.outsideAngular),r.switchMap((function(){return o.isPlatformBrowser(f)?import("firebase/remote-config"):n.EMPTY})),r.map((function(){return i.ɵfirebaseAppFactory(e,s,t)})),r.map((function(e){return e.remoteConfig()})),r.tap((function(e){u&&(e.settings=u),a&&(e.defaultConfig=a)})),r.startWith(void 0),r.shareReplay({bufferSize:1,refCount:!1})),d=l.pipe(r.filter((function(e){return!!e}))),m=n.of(Object.keys(a||{}).reduce((function(e,t){var n;return Object.assign(Object.assign({},e),((n={})[t]=new y("default",a[t].toString()),n))}),{})),h=r.map((function(e){return Object.keys(e).filter((function(t){return"default"!==e[t].getSource()})).reduce((function(t,n){var r;return Object.assign(Object.assign({},t),((r={})[n]=e[n],r))}),{})})),j=d.pipe(r.switchMap((function(e){return e.activate().then((function(){return e.ensureInitialized()})).then((function(){return e.getAll()}))})),h),v=d.pipe(r.switchMap((function(e){return s.runOutsideAngular((function(){return e.fetchAndActivate().then((function(){return e.ensureInitialized()})).then((function(){return e.getAll()}))}))})),h);return this.parameters=n.concat(m,j,v).pipe(b(l),i.ɵkeepUnstableUntilFirstFactory(p),r.shareReplay({bufferSize:1,refCount:!0})),this.changes=this.parameters.pipe(r.switchMap((function(e){return n.of.apply(void 0,c(e))})),r.groupBy((function(e){return e.key})),r.mergeMap((function(e){return e.pipe(r.distinctUntilChanged())}))),this.strings=g(this.parameters,"strings"),this.booleans=g(this.parameters,"booleans"),this.numbers=g(this.parameters,"numbers"),i.ɵlazySDKProxy(this,d,s)};h.decorators=[{type:t.Injectable,args:[{providedIn:"any"}]}],h.ctorParameters=function(){return[{type:void 0,decorators:[{type:t.Inject,args:[i.FIREBASE_OPTIONS]}]},{type:void 0,decorators:[{type:t.Optional},{type:t.Inject,args:[i.FIREBASE_APP_NAME]}]},{type:void 0,decorators:[{type:t.Optional},{type:t.Inject,args:[s]}]},{type:void 0,decorators:[{type:t.Optional},{type:t.Inject,args:[f]}]},{type:t.NgZone},{type:Object,decorators:[{type:t.Inject,args:[t.PLATFORM_ID]}]}]},h.ɵprov=t.ɵɵdefineInjectable({factory:function(){return new h(t.ɵɵinject(i.FIREBASE_OPTIONS),t.ɵɵinject(i.FIREBASE_APP_NAME,8),t.ɵɵinject(s,8),t.ɵɵinject(f,8),t.ɵɵinject(t.NgZone),t.ɵɵinject(t.PLATFORM_ID))},token:h,providedIn:"any"});var j=function(e){return function(t){return new n.Observable((function(n){var r=!1,i=setTimeout((function(){n.complete(),r=!0}),e);return t.subscribe({next:function(e){r||n.next(e)},error:function(e){r||(clearTimeout(i),n.error(e))},complete:function(){r||(clearTimeout(i),n.complete())}})}))}},v=function(e){switch(typeof e){case"string":return"asString";case"boolean":return"asBoolean";case"number":return"asNumber";default:return"asString"}};function O(e){return void 0===e&&(e="strings"),n.pipe(r.map((function(t){return t.reduce((function(t,n){var r;return Object.assign(Object.assign({},t),((r={})[n.key]="object"==typeof e?n[v(e[n.key])]():n[p[e]](),r))}),"object"==typeof e?e:{})})),r.distinctUntilChanged((function(e,t){return JSON.stringify(e)===JSON.stringify(t)})))}var S=function(){};S.decorators=[{type:t.NgModule,args:[{providers:[h]}]}],e.AngularFireRemoteConfig=h,e.AngularFireRemoteConfigModule=S,e.DEFAULTS=f,e.Parameter=d,e.SETTINGS=s,e.Value=y,e.budget=j,e.filterFresh=function(e){return m((function(t){return t.fetchTimeMillis+e>=(new Date).getTime()}))},e.filterRemote=function(){return m((function(e){return"remote"===e.getSource()}))},e.mapToObject=O,e.scanToObject=function(e){return void 0===e&&(e="strings"),n.pipe(r.scan((function(t,n){var r;return Object.assign(Object.assign({},t),((r={})[n.key]="object"==typeof e?n[v(e[n.key])]():n[p[e]](),r))}),"object"==typeof e?e:{}),r.debounceTime(1),j(10),r.distinctUntilChanged((function(e,t){return JSON.stringify(e)===JSON.stringify(t)})))},Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=angular-fire-remote-config.umd.min.js.map