Skip to content
Permalink
Browse files

fix: fixed some stuff

  • Loading branch information
ike18t committed Feb 19, 2018
1 parent 9dc9cbb commit e12158f184a250e5a90392106823b53a71ca4058
@@ -1,2 +1,4 @@
export { FlipadelphiaComponent } from './src/flipadelphia.component';
export { FeatureFlipDirective } from './src/feature-flip.directive';
export { FlipadelphiaModule } from './src/flipadelphia.module';
export { FeatureToggles } from './src/feature-toggles';
@@ -41,11 +41,13 @@
},
"devDependencies": {
"@angular/common": "5.x",
"@angular/compiler": "5.x",
"@angular/compiler": "^5.2.5",
"@angular/compiler-cli": "^5.2.5",
"@angular/core": "5.x",
"@angular/forms": "5.x",
"@angular/platform-browser": "5.x",
"@angular/platform-browser-dynamic": "5.x",
"@angular/platform-server": "^5.2.5",
"@types/core-js": "^0.9.43",
"@types/jasmine": "^2.5.53",
"@types/node": "^8.0.17",
@@ -64,7 +66,7 @@
"ts-mocks": "^2.0.0",
"ts-node": "^4.1.0",
"tslint": "^5.9.1",
"typescript": "2.6.x",
"typescript": "^2.8.0-dev.20180217",
"zone.js": "^0.8.14"
},
"directories": {
@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser'
import { By } from '@angular/platform-browser';
import { Mock } from 'ts-mocks';
import { FeatureFlipDirective } from './feature-flip.directive';
import { FLIPPER_SERVICE, FlipperService } from './flipper.service';
@@ -11,9 +11,9 @@ import { FLIPPER_SERVICE, FlipperService } from './flipper.service';
<div [feature-flip]="'foo'">'hi'</div>
`
})
export class ExampleComponentContainer {}
class ExampleComponentContainer {}

xdescribe('FeatureFlip', () => {
describe('FeatureFlip', () => {
let fixture: ComponentFixture<ExampleComponentContainer>;

beforeEach(async(() => {
@@ -1,17 +1,21 @@
import { NgIf, NgIfContext } from '@angular/common';
import { Directive, Inject, Input, TemplateRef, ViewContainerRef } from '@angular/core';
import { NgIf } from '@angular/common';
import { Directive, Inject, Input, OnInit, TemplateRef, ViewContainerRef } from '@angular/core';
import { FLIPPER_SERVICE, FlipperService } from './flipper.service';

@Directive({
selector: '[feature-flip]',
})
export class FeatureFlipDirective extends NgIf {
export class FeatureFlipDirective extends NgIf implements OnInit {
@Input('feature-flip') featureFlip: string;

constructor(@Inject(FLIPPER_SERVICE) readonly flipperService: FlipperService,
readonly view: ViewContainerRef,
readonly template: TemplateRef<NgIfContext>) {
view: ViewContainerRef,
template: TemplateRef<any>) {
super(view, template);
this.ngIf = this.flipperService.isEnabled(this.featureFlip);
this.ngIf = false;
}

async ngOnInit() {
this.ngIf = await this.flipperService.isEnabled(this.featureFlip);
}
}
@@ -19,11 +19,12 @@ import { FLIPPER_SERVICE, FlipperService } from './flipper.service';
`
})
export class FlipadelphiaComponent {
toggles = Object.keys(this.featureToggles)
.map(key => ({ key, value: this.featureToggles[key] }));
toggles: any;

constructor(@Inject(FEATURE_TOGGLES) private readonly featureToggles: FeatureToggles,
@Inject(FLIPPER_SERVICE) private readonly flipperService: FlipperService) {}
constructor(@Inject(FEATURE_TOGGLES) readonly featureToggles: FeatureToggles,
@Inject(FLIPPER_SERVICE) private readonly flipperService: FlipperService) {
this.loadToggles(featureToggles);
}

public setToggleState(target: HTMLInputElement) {
if (target.checked) {
@@ -32,4 +33,10 @@ export class FlipadelphiaComponent {
this.flipperService.disable(target.id);
}
}

private async loadToggles(featureToggles: FeatureToggles) {
const toggles = Object.keys(featureToggles);
const values = await Promise.all(toggles.map(key => this.flipperService.isEnabled(key)));
this.toggles = toggles.map((toggle, index) => ({ key: toggle, value: values[index] }));
}
}
@@ -1,5 +1,6 @@
import { CommonModule } from '@angular/common';
import { ModuleWithProviders, NgModule, Type } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FeatureFlipDirective } from './feature-flip.directive';
import { FEATURE_TOGGLES, FeatureToggles } from './feature-toggles';
import { FlipadelphiaComponent } from './flipadelphia.component';
@@ -19,6 +20,7 @@ import { LOCAL_STORAGE, LocalStorageFlipperService } from './local-storage-flipp
FlipadelphiaComponent
],
imports: [
BrowserModule,
CommonModule
],
providers: [
@@ -12,7 +12,7 @@ export class LocalStorageFlipperService implements FlipperService {
@Inject(LOCAL_STORAGE) private readonly localStorage: Storage) {}

private get enabledToggles() {
return JSON.parse(this.localStorage.getItem(this.LOCAL_STORAGE_KEY) || '') || [] as string[];
return JSON.parse(this.localStorage.getItem(this.LOCAL_STORAGE_KEY) as string) || [] as string[];
}

async disable(toggleName: string): Promise<void> {

0 comments on commit e12158f

Please sign in to comment.
You can’t perform that action at this time.