ngx-feature-toggle-demo
Version:
Your module to handle with feature toggles in Angular applications easier.
35 lines (29 loc) • 1 kB
text/typescript
import { Component, Input, OnInit, DoCheck } from '@angular/core';
import { set, FeatureToggleServiceConfig } from 'feature-toggle-service';
export class FeatureToggleProviderComponent implements DoCheck, OnInit {
features: FeatureToggleServiceConfig = {};
private currentConfig: FeatureToggleServiceConfig = {};
ngOnInit() {
if (typeof this.features !== 'object') {
throw new Error('Attribute `features` should not be null or empty');
}
this.setFeatureToggles();
}
ngDoCheck() {
this.setFeatureToggles();
}
private setFeatureToggles() {
if (this.currentConfig !== this.features) {
// Using `Object.assign()` method for bundle size decreasing purposes
// It's required since it needs a new memory reference
// for the new object value
this.currentConfig = Object.assign({}, this.features);
set(this.features);
}
}
}