Skip to content
Permalink
Browse files

feat: add local storage flipper and refactor stuff

  • Loading branch information
ike18t committed Feb 18, 2018
1 parent 68e3a2a commit 1a86c4ce72bff41bbc1bd48e50157e58965385c3
@@ -0,0 +1,2 @@
export { FlipadelphiaModule } from './src/flipadelphia.module';
export { FeatureToggles } from './src/feature-toggles';
@@ -36,6 +36,7 @@
},
"homepage": "https://github.com/ike18t/flipadelphia#readme",
"peerDependencies": {
"@angular/common": "5.x",
"@angular/core": "5.x"
},
"devDependencies": {
@@ -67,7 +68,7 @@
"zone.js": "^0.8.14"
},
"directories": {
"lib": "lib"
"src": "src"
},
"dependencies": {}
}
@@ -0,0 +1,45 @@
import { Component } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Mock } from 'ts-mocks';
import { FeatureFlipDirective } from './feature-flip.directive';
import { FLIPPER_SERVICE, FlipperService } from './flipper.service';

@Component({
selector: 'example-component-container',
template: `
<div [feature-flip]="'foo'">'hi'</div>
`
})
export class ExampleComponentContainer {}

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

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
ExampleComponentContainer,
FeatureFlipDirective
],
providers: [
{ provide: FLIPPER_SERVICE,
useValue: new Mock<FlipperService>({ disable: Mock.ANY_FUNC,
enable: Mock.ANY_FUNC,
isEnabled: () => false }).Object },
// { provide: TemplateRef, useValue: new Mock<TemplateRef<any>>().Object },
// { provide: ViewContainerRef, useValue: new Mock<ViewContainerRef>({ clear: Mock.ANY_FUNC }).Object }
]
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(ExampleComponentContainer);
fixture.detectChanges();
});
}));

it('does not render the element that has the directive if the toggle value is false', () => {
console.log(fixture.debugElement.nativeElement.innerHTML);
// const debugElement = fixture.debugElement.query(By.css('div'));
// expect(debugElement).toBeNull();
});
});
@@ -0,0 +1,17 @@
import { NgIf, NgIfContext } from '@angular/common';
import { Directive, Inject, Input, TemplateRef, ViewContainerRef } from '@angular/core';
import { FLIPPER_SERVICE, FlipperService } from './flipper.service';

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

constructor(@Inject(FLIPPER_SERVICE) readonly flipperService: FlipperService,
readonly view: ViewContainerRef,
readonly template: TemplateRef<NgIfContext>) {
super(view, template);
this.ngIf = this.flipperService.isEnabled(this.featureFlip);
}
}
@@ -3,7 +3,7 @@ import { By } from '@angular/platform-browser';
import { Mock } from 'ts-mocks';
import { FEATURE_TOGGLES } from './feature-toggles';
import { FlipadelphiaComponent } from './flipadelphia.component';
import { FLIPPER_SERVICE, FlipperService } from './flipper-service';
import { FLIPPER_SERVICE, FlipperService } from './flipper.service';

describe('FlipadelphiaComponent', () => {
let fixture: ComponentFixture<FlipadelphiaComponent>;
@@ -1,6 +1,6 @@
import { Component, Inject } from '@angular/core';
import { FEATURE_TOGGLES, FeatureToggles } from './feature-toggles';
import { FLIPPER_SERVICE, FlipperService } from './flipper-service';
import { FLIPPER_SERVICE, FlipperService } from './flipper.service';

@Component({
selector: 'flipadelphia',
@@ -1,19 +1,28 @@
import { CommonModule } from '@angular/common';
import { ModuleWithProviders, NgModule, Type } from '@angular/core';
import { FeatureFlipDirective } from './feature-flip.directive';
import { FEATURE_TOGGLES, FeatureToggles } from './feature-toggles';
import { FlipadelphiaComponent } from './flipadelphia.component';
import { FLIPPER_SERVICE, FlipperService } from './flipper-service';
import { LOCAL_STORAGE, LocalStorageFlipperService } from './local-storage-flipper-service';
import { FLIPPER_SERVICE, FlipperService } from './flipper.service';
import { LOCAL_STORAGE, LocalStorageFlipperService } from './local-storage-flipper.service';

@NgModule({
declarations: [
FeatureFlipDirective,
FlipadelphiaComponent
],
entryComponents: [
FlipadelphiaComponent
],
exports: [
FeatureFlipDirective,
FlipadelphiaComponent
],
imports: [
CommonModule
],
providers: [
LocalStorageFlipperService
]
})
export class FlipadelphiaModule {
File renamed without changes.
@@ -1,5 +1,5 @@
import { Mock } from 'ts-mocks';
import { LocalStorageFlipperService } from './local-storage-flipper-service';
import { LocalStorageFlipperService } from './local-storage-flipper.service';

describe('LocalStorageFlipperService', () => {
let service: LocalStorageFlipperService;
@@ -1,6 +1,6 @@
import { Inject, Injectable, InjectionToken } from '@angular/core';
import { FEATURE_TOGGLES, FeatureToggles } from './feature-toggles';
import { FlipperService } from './flipper-service';
import { FlipperService } from './flipper.service';

export const LOCAL_STORAGE = new InjectionToken<Storage>('LocalStorage');

@@ -4,9 +4,11 @@
"arrow-parens": false,
"completed-docs": false,
"interface-name": false,
"max-classes-per-file": false,
"member-access": false,
"newline-before-return": false,
"newline-per-chained-call": false,
"no-any": false,
"no-floating-promises": false,
"no-implicit-dependencies": [true, "dev"],
"no-magic-numbers": false,

0 comments on commit 1a86c4c

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