UNPKG

ng-config-cat

Version:

An Angular service for ConfigCat

16 lines (14 loc) 7.21 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("configcat-common"),require("@angular/core"),require("@angular/common"),require("configcat-js"),require("rxjs"),require("rxjs/operators"),require("rxjs/internal-compatibility")):"function"==typeof define&&define.amd?define("ng-config-cat",["exports","configcat-common","@angular/core","@angular/common","configcat-js","rxjs","rxjs/operators","rxjs/internal-compatibility"],t):t((e=e||self)["ng-config-cat"]={},e["configcat-common"],e.ng.core,e.ng.common,e["configcat-js"],e.rxjs,e.rxjs.operators,e.rxjs["internal-compatibility"])}(this,(function(e,t,n,r,o,i,a,u){"use strict";var c=new n.InjectionToken("NgConfigCatOptions"),l=function(e,t){return(l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)}; /*! ***************************************************************************** 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. ***************************************************************************** */function f(e,t){function n(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}Object.create;Object.create;var s=function(e){e.logLevel&&e.logLevel!==t.LogLevel.Off&&(this.logger=o.createConsoleLogger(e.logLevel)),this.requestTimeoutMs=e.requestTimeout},g=function(e){function t(t){void 0===t&&(t={});var n=e.call(this,t)||this;return n.pollIntervalSeconds=t.pollInterval,n}return f(t,e),t}(s),p=function(){function e(){}return e.prototype.getValue=function(e,t,n){return u.fromPromise(this.client.getValueAsync(e,t,n))},e.prototype.getAllKeys=function(){return this.client.getAllKeysAsync()},e.prototype.forceRefresh=function(){return this.client.forceRefreshAsync()},e}(),d=function(e){function t(t,n){var r=e.call(this)||this;return r.configChangeNotificator=new i.Subject,r.client=o.createClientWithAutoPoll(t,{pollIntervalSeconds:n.pollIntervalSeconds,configChanged:function(){return r.configChangeNotificator.next()},logger:n.logger,requestTimeoutMs:n.requestTimeoutMs}),r}return f(t,e),t.prototype.getValue=function(t,n,r){var o=this;return i.merge(e.prototype.getValue.call(this,t,n,r),this.configChangeNotificator.pipe(a.switchMap((function(){return e.prototype.getValue.call(o,t,n,r)})))).pipe(a.distinctUntilChanged())},t}(p),y=function(e){function t(t,n){var r=e.call(this)||this;return r.client=o.createClientWithLazyLoad(t,n),r}return f(t,e),t}(p),h=function(e){function t(t,n){var r=e.call(this)||this;return r.client=o.createClientWithManualPoll(t,n),r}return f(t,e),t}(p),C=function(e){function t(t){void 0===t&&(t={});var n=e.call(this,t)||this;return n.cacheTimeToLiveSeconds=t.cacheTimeToLive,n}return f(t,e),t}(s),v=function(e){function t(t){return void 0===t&&(t={}),e.call(this,t)||this}return f(t,e),t}(s),m=function(){function e(e){var t=e.sdkKey,n=e.configuration,r=void 0===n?new g:n;if(r instanceof g)this.configCatClient=new d(t,r);else if(r instanceof C)this.configCatClient=new y(t,r);else{if(!(r instanceof v))throw new TypeError("NgConfigCat configuration should be represent by an instance of PollingModeConfiguration class");this.configCatClient=new h(t,r)}}return e.prototype.getValue=function(e,t,n){return this.configCatClient.getValue(e,t,n)},e.prototype.getAllKeys=function(){return this.configCatClient.getAllKeys()},e.prototype.forceRefresh=function(){return this.configCatClient.forceRefresh()},e}();m.ɵprov=n.ɵɵdefineInjectable({factory:function(){return new m(n.ɵɵinject(c))},token:m,providedIn:"root"}),m.decorators=[{type:n.Injectable,args:[{providedIn:"root"}]}],m.ctorParameters=function(){return[{type:void 0,decorators:[{type:n.Inject,args:[c]}]}]};var b=function(){function e(e,t,n){this.viewContainerRef=e,this.templateRef=t,this.ngConfigCatService=n,this.destroy$=new i.Subject,this.viewRef=null}return e.prototype.ngOnInit=function(){if(!this.featureName)throw new Error("Attribute `ngConfigCatFeatureEnabled` should not be null or empty");this.render()},e.prototype.ngOnDestroy=function(){this.destroy$.next()},e.prototype.render=function(){var e=this;this.ngConfigCatService.getValue(this.featureName,this.defaultValue,this.user).pipe(a.takeUntil(this.destroy$),a.map((function(t){return t===e.shouldFeatureBeEnabled}))).subscribe((function(t){t?(e.viewRef=e.viewContainerRef.createEmbeddedView(e.templateRef),e.viewRef.markForCheck()):(e.viewContainerRef.clear(),e.viewRef&&(e.viewRef.destroy(),e.viewRef=null))}))},e}();b.decorators=[{type:n.Directive,args:[{selector:"[ngConfigCatFeatureBase]"}]}],b.ctorParameters=function(){return[{type:n.ViewContainerRef},{type:n.TemplateRef},{type:m}]};var w=function(e){function t(t,n,r){var o=e.call(this,t,n,r)||this;return o.defaultValue=!1,o.shouldFeatureBeEnabled=!0,o}return f(t,e),t}(b);w.decorators=[{type:n.Directive,args:[{selector:"[ngConfigCatFeatureEnabled]"}]}],w.ctorParameters=function(){return[{type:n.ViewContainerRef},{type:n.TemplateRef},{type:m}]},w.propDecorators={featureName:[{type:n.Input,args:["ngConfigCatFeatureEnabled"]}],defaultValue:[{type:n.Input,args:["ngConfigCatDefault"]}],user:[{type:n.Input,args:["ngConfigCatUser"]}]};var j=function(e){function t(t,n,r){var o=e.call(this,t,n,r)||this;return o.defaultValue=!1,o.shouldFeatureBeEnabled=!1,o}return f(t,e),t}(b);j.decorators=[{type:n.Directive,args:[{selector:"[ngConfigCatFeatureDisabled]"}]}],j.ctorParameters=function(){return[{type:n.ViewContainerRef},{type:n.TemplateRef},{type:m}]},j.propDecorators={featureName:[{type:n.Input,args:["ngConfigCatFeatureDisabled"]}],defaultValue:[{type:n.Input,args:["ngConfigCatDefault"]}],user:[{type:n.Input,args:["ngConfigCatUser"]}]};var R=function(){function e(e){if(e)throw new Error("NgConfigCatModule is already loaded. Import it in the AppModule only.")}return e.forRoot=function(t){return{ngModule:e,providers:[{provide:c,useValue:t}]}},e}();R.decorators=[{type:n.NgModule,args:[{imports:[r.CommonModule],declarations:[w,j],exports:[w,j]}]}],R.ctorParameters=function(){return[{type:R,decorators:[{type:n.Optional},{type:n.SkipSelf}]}]},Object.defineProperty(e,"LogLevel",{enumerable:!0,get:function(){return t.LogLevel}}),e.AutoPollingModeConfiguration=g,e.LazyPollingModeConfiguration=C,e.ManualPollingModeConfiguration=v,e.NgConfigCatFeatureDisabledDirective=j,e.NgConfigCatFeatureEnabledDirective=w,e.NgConfigCatModule=R,e.NgConfigCatService=m,e.ɵa=c,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=ng-config-cat.umd.min.js.map