From 65e68e525b407b317bba0e5828fcc696ccd51d6f Mon Sep 17 00:00:00 2001 From: Filip Lauc Date: Sat, 16 Jun 2018 15:33:52 +0200 Subject: [PATCH] feat: Adding directives and pipes :construction: --- .../click-outside.directive.spec.ts | 8 +++++ .../click-outside/click-outside.directive.ts | 10 ++++++ .../click-outside.module.spec.ts | 13 ++++++++ .../click-outside/click-outside.module.ts | 16 ++++++++++ .../form-touch-on-hover.directive.spec.ts | 8 +++++ .../form-touch-on-hover.directive.ts | 10 ++++++ .../form-touch-on-hover.module.spec.ts | 13 ++++++++ .../form-touch-on-hover.module.ts | 16 ++++++++++ .../stop-propagation.directive.spec.ts | 8 +++++ .../stop-propagation.directive.ts | 10 ++++++ .../stop-propagation.module.spec.ts | 13 ++++++++ .../stop-propagation.module.ts | 16 ++++++++++ projects/ng-helpers/src/helpers/rx-destroy.ts | 31 +++++++++++++++++++ .../src/lib/ng-helpers.component.spec.ts | 25 --------------- .../src/lib/ng-helpers.component.ts | 19 ------------ .../ng-helpers/src/lib/ng-helpers.module.ts | 10 ------ .../src/lib/ng-helpers.service.spec.ts | 15 --------- .../ng-helpers/src/lib/ng-helpers.service.ts | 9 ------ .../src/pipes/enum/enum.module.spec.ts | 13 ++++++++ .../ng-helpers/src/pipes/enum/enum.module.ts | 16 ++++++++++ .../src/pipes/enum/enum.pipe.spec.ts | 8 +++++ .../ng-helpers/src/pipes/enum/enum.pipe.ts | 12 +++++++ .../pipes/sanitize/sanitize.module.spec.ts | 13 ++++++++ .../src/pipes/sanitize/sanitize.module.ts | 16 ++++++++++ .../src/pipes/sanitize/sanitize.pipe.spec.ts | 8 +++++ .../src/pipes/sanitize/sanitize.pipe.ts | 12 +++++++ projects/ng-helpers/tslint.json | 4 +-- 27 files changed, 272 insertions(+), 80 deletions(-) create mode 100644 projects/ng-helpers/src/directives/click-outside/click-outside.directive.spec.ts create mode 100644 projects/ng-helpers/src/directives/click-outside/click-outside.directive.ts create mode 100644 projects/ng-helpers/src/directives/click-outside/click-outside.module.spec.ts create mode 100644 projects/ng-helpers/src/directives/click-outside/click-outside.module.ts create mode 100644 projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.directive.spec.ts create mode 100644 projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.directive.ts create mode 100644 projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.module.spec.ts create mode 100644 projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.module.ts create mode 100644 projects/ng-helpers/src/directives/stop-propagation/stop-propagation.directive.spec.ts create mode 100644 projects/ng-helpers/src/directives/stop-propagation/stop-propagation.directive.ts create mode 100644 projects/ng-helpers/src/directives/stop-propagation/stop-propagation.module.spec.ts create mode 100644 projects/ng-helpers/src/directives/stop-propagation/stop-propagation.module.ts create mode 100644 projects/ng-helpers/src/helpers/rx-destroy.ts delete mode 100644 projects/ng-helpers/src/lib/ng-helpers.component.spec.ts delete mode 100644 projects/ng-helpers/src/lib/ng-helpers.component.ts delete mode 100644 projects/ng-helpers/src/lib/ng-helpers.module.ts delete mode 100644 projects/ng-helpers/src/lib/ng-helpers.service.spec.ts delete mode 100644 projects/ng-helpers/src/lib/ng-helpers.service.ts create mode 100644 projects/ng-helpers/src/pipes/enum/enum.module.spec.ts create mode 100644 projects/ng-helpers/src/pipes/enum/enum.module.ts create mode 100644 projects/ng-helpers/src/pipes/enum/enum.pipe.spec.ts create mode 100644 projects/ng-helpers/src/pipes/enum/enum.pipe.ts create mode 100644 projects/ng-helpers/src/pipes/sanitize/sanitize.module.spec.ts create mode 100644 projects/ng-helpers/src/pipes/sanitize/sanitize.module.ts create mode 100644 projects/ng-helpers/src/pipes/sanitize/sanitize.pipe.spec.ts create mode 100644 projects/ng-helpers/src/pipes/sanitize/sanitize.pipe.ts diff --git a/projects/ng-helpers/src/directives/click-outside/click-outside.directive.spec.ts b/projects/ng-helpers/src/directives/click-outside/click-outside.directive.spec.ts new file mode 100644 index 0000000..54be5ed --- /dev/null +++ b/projects/ng-helpers/src/directives/click-outside/click-outside.directive.spec.ts @@ -0,0 +1,8 @@ +import { ClickOutsideDirective } from './click-outside.directive'; + +describe('ClickOutsideDirective', () => { + it('should create an instance', () => { + const directive = new ClickOutsideDirective(); + expect(directive).toBeTruthy(); + }); +}); diff --git a/projects/ng-helpers/src/directives/click-outside/click-outside.directive.ts b/projects/ng-helpers/src/directives/click-outside/click-outside.directive.ts new file mode 100644 index 0000000..d20edbc --- /dev/null +++ b/projects/ng-helpers/src/directives/click-outside/click-outside.directive.ts @@ -0,0 +1,10 @@ +import { Directive } from '@angular/core'; + +@Directive({ + selector: '[libClickOutside]' +}) +export class ClickOutsideDirective { + + constructor() { } + +} diff --git a/projects/ng-helpers/src/directives/click-outside/click-outside.module.spec.ts b/projects/ng-helpers/src/directives/click-outside/click-outside.module.spec.ts new file mode 100644 index 0000000..12d94a5 --- /dev/null +++ b/projects/ng-helpers/src/directives/click-outside/click-outside.module.spec.ts @@ -0,0 +1,13 @@ +import { ClickOutsideModule } from './click-outside.module'; + +describe('ClickOutsideModule', () => { + let clickOutsideModule: ClickOutsideModule; + + beforeEach(() => { + clickOutsideModule = new ClickOutsideModule(); + }); + + it('should create an instance', () => { + expect(clickOutsideModule).toBeTruthy(); + }); +}); diff --git a/projects/ng-helpers/src/directives/click-outside/click-outside.module.ts b/projects/ng-helpers/src/directives/click-outside/click-outside.module.ts new file mode 100644 index 0000000..3b2a65c --- /dev/null +++ b/projects/ng-helpers/src/directives/click-outside/click-outside.module.ts @@ -0,0 +1,16 @@ +import {CommonModule} from '@angular/common'; +import {NgModule} from '@angular/core'; +import {ClickOutsideDirective} from './click-outside.directive'; + +@NgModule({ + imports: [ + CommonModule + ], + declarations: [ + ClickOutsideDirective + ], + exports: [ + ClickOutsideDirective + ] +}) +export class ClickOutsideModule { } diff --git a/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.directive.spec.ts b/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.directive.spec.ts new file mode 100644 index 0000000..2c41ca8 --- /dev/null +++ b/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.directive.spec.ts @@ -0,0 +1,8 @@ +import { FormTouchOnHoverDirective } from './form-touch-on-hover.directive'; + +describe('FormTouchOnHoverDirective', () => { + it('should create an instance', () => { + const directive = new FormTouchOnHoverDirective(); + expect(directive).toBeTruthy(); + }); +}); diff --git a/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.directive.ts b/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.directive.ts new file mode 100644 index 0000000..596da01 --- /dev/null +++ b/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.directive.ts @@ -0,0 +1,10 @@ +import { Directive } from '@angular/core'; + +@Directive({ + selector: '[libFormTouchOnHover]' +}) +export class FormTouchOnHoverDirective { + + constructor() { } + +} diff --git a/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.module.spec.ts b/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.module.spec.ts new file mode 100644 index 0000000..830e430 --- /dev/null +++ b/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.module.spec.ts @@ -0,0 +1,13 @@ +import { FormTouchOnHoverModule } from './form-touch-on-hover.module'; + +describe('FormTouchOnHoverModule', () => { + let formTouchOnHoverModule: FormTouchOnHoverModule; + + beforeEach(() => { + formTouchOnHoverModule = new FormTouchOnHoverModule(); + }); + + it('should create an instance', () => { + expect(formTouchOnHoverModule).toBeTruthy(); + }); +}); diff --git a/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.module.ts b/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.module.ts new file mode 100644 index 0000000..fef7135 --- /dev/null +++ b/projects/ng-helpers/src/directives/form-touch-on-hover/form-touch-on-hover.module.ts @@ -0,0 +1,16 @@ +import {CommonModule} from '@angular/common'; +import {NgModule} from '@angular/core'; +import {FormTouchOnHoverDirective} from './form-touch-on-hover.directive'; + +@NgModule({ + imports: [ + CommonModule + ], + declarations: [ + FormTouchOnHoverDirective + ], + exports: [ + FormTouchOnHoverDirective + ] +}) +export class FormTouchOnHoverModule { } diff --git a/projects/ng-helpers/src/directives/stop-propagation/stop-propagation.directive.spec.ts b/projects/ng-helpers/src/directives/stop-propagation/stop-propagation.directive.spec.ts new file mode 100644 index 0000000..34b87eb --- /dev/null +++ b/projects/ng-helpers/src/directives/stop-propagation/stop-propagation.directive.spec.ts @@ -0,0 +1,8 @@ +import { StopPropagationDirective } from './stop-propagation.directive'; + +describe('StopPropagationDirective', () => { + it('should create an instance', () => { + const directive = new StopPropagationDirective(); + expect(directive).toBeTruthy(); + }); +}); diff --git a/projects/ng-helpers/src/directives/stop-propagation/stop-propagation.directive.ts b/projects/ng-helpers/src/directives/stop-propagation/stop-propagation.directive.ts new file mode 100644 index 0000000..98507db --- /dev/null +++ b/projects/ng-helpers/src/directives/stop-propagation/stop-propagation.directive.ts @@ -0,0 +1,10 @@ +import { Directive } from '@angular/core'; + +@Directive({ + selector: '[libStopPropagation]' +}) +export class StopPropagationDirective { + + constructor() { } + +} diff --git a/projects/ng-helpers/src/directives/stop-propagation/stop-propagation.module.spec.ts b/projects/ng-helpers/src/directives/stop-propagation/stop-propagation.module.spec.ts new file mode 100644 index 0000000..c5c60a2 --- /dev/null +++ b/projects/ng-helpers/src/directives/stop-propagation/stop-propagation.module.spec.ts @@ -0,0 +1,13 @@ +import { StopPropagationModule } from './stop-propagation.module'; + +describe('StopPropagationModule', () => { + let stopPropagationModule: StopPropagationModule; + + beforeEach(() => { + stopPropagationModule = new StopPropagationModule(); + }); + + it('should create an instance', () => { + expect(stopPropagationModule).toBeTruthy(); + }); +}); diff --git a/projects/ng-helpers/src/directives/stop-propagation/stop-propagation.module.ts b/projects/ng-helpers/src/directives/stop-propagation/stop-propagation.module.ts new file mode 100644 index 0000000..8774b68 --- /dev/null +++ b/projects/ng-helpers/src/directives/stop-propagation/stop-propagation.module.ts @@ -0,0 +1,16 @@ +import {CommonModule} from '@angular/common'; +import {NgModule} from '@angular/core'; +import {StopPropagationDirective} from './stop-propagation.directive'; + +@NgModule({ + imports: [ + CommonModule + ], + declarations: [ + StopPropagationDirective + ], + exports: [ + StopPropagationDirective + ] +}) +export class StopPropagationModule { } diff --git a/projects/ng-helpers/src/helpers/rx-destroy.ts b/projects/ng-helpers/src/helpers/rx-destroy.ts new file mode 100644 index 0000000..2a1decb --- /dev/null +++ b/projects/ng-helpers/src/helpers/rx-destroy.ts @@ -0,0 +1,31 @@ +import {OnDestroy} from '@angular/core'; +import {Subject} from 'rxjs'; + +/** + * Uses the destroyed$ subject to indicate that the component was destroyed + * + * @example + * class SomeComponent extends RxDestroy { + * ngOnInit() { + * interval(1000) + * .pipe( + * takeUntil(this.destroyed$) + * ) + * .subscribe(_ => {}); + * } + * } + */ +export class RxDestroy implements OnDestroy { + /** + * Used like this in classes that extend RxDestroy: someObservable$.takeUntil(this.destroyed$) + */ + destroyed$ = new Subject(); + + /** + * Calls next() on this.destroyed$ to cancel all listeners + */ + ngOnDestroy() { + this.destroyed$.next(); + this.destroyed$.complete(); + } +} diff --git a/projects/ng-helpers/src/lib/ng-helpers.component.spec.ts b/projects/ng-helpers/src/lib/ng-helpers.component.spec.ts deleted file mode 100644 index 3ca4006..0000000 --- a/projects/ng-helpers/src/lib/ng-helpers.component.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { NgHelpersComponent } from './ng-helpers.component'; - -describe('NgHelpersComponent', () => { - let component: NgHelpersComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ NgHelpersComponent ] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(NgHelpersComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/projects/ng-helpers/src/lib/ng-helpers.component.ts b/projects/ng-helpers/src/lib/ng-helpers.component.ts deleted file mode 100644 index f283e2d..0000000 --- a/projects/ng-helpers/src/lib/ng-helpers.component.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Component, OnInit } from '@angular/core'; - -@Component({ - selector: 'lib-ng-helpers', - template: ` -

- ng-helpers works! -

- `, - styles: [] -}) -export class NgHelpersComponent implements OnInit { - - constructor() { } - - ngOnInit() { - } - -} diff --git a/projects/ng-helpers/src/lib/ng-helpers.module.ts b/projects/ng-helpers/src/lib/ng-helpers.module.ts deleted file mode 100644 index 6ea2d33..0000000 --- a/projects/ng-helpers/src/lib/ng-helpers.module.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { NgModule } from '@angular/core'; -import { NgHelpersComponent } from './ng-helpers.component'; - -@NgModule({ - imports: [ - ], - declarations: [NgHelpersComponent], - exports: [NgHelpersComponent] -}) -export class NgHelpersModule { } diff --git a/projects/ng-helpers/src/lib/ng-helpers.service.spec.ts b/projects/ng-helpers/src/lib/ng-helpers.service.spec.ts deleted file mode 100644 index b252d9e..0000000 --- a/projects/ng-helpers/src/lib/ng-helpers.service.spec.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { TestBed, inject } from '@angular/core/testing'; - -import { NgHelpersService } from './ng-helpers.service'; - -describe('NgHelpersService', () => { - beforeEach(() => { - TestBed.configureTestingModule({ - providers: [NgHelpersService] - }); - }); - - it('should be created', inject([NgHelpersService], (service: NgHelpersService) => { - expect(service).toBeTruthy(); - })); -}); diff --git a/projects/ng-helpers/src/lib/ng-helpers.service.ts b/projects/ng-helpers/src/lib/ng-helpers.service.ts deleted file mode 100644 index bc9ee0d..0000000 --- a/projects/ng-helpers/src/lib/ng-helpers.service.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Injectable } from '@angular/core'; - -@Injectable({ - providedIn: 'root' -}) -export class NgHelpersService { - - constructor() { } -} diff --git a/projects/ng-helpers/src/pipes/enum/enum.module.spec.ts b/projects/ng-helpers/src/pipes/enum/enum.module.spec.ts new file mode 100644 index 0000000..12d38b7 --- /dev/null +++ b/projects/ng-helpers/src/pipes/enum/enum.module.spec.ts @@ -0,0 +1,13 @@ +import { EnumModule } from './enum.module'; + +describe('EnumModule', () => { + let enumModule: EnumModule; + + beforeEach(() => { + enumModule = new EnumModule(); + }); + + it('should create an instance', () => { + expect(enumModule).toBeTruthy(); + }); +}); diff --git a/projects/ng-helpers/src/pipes/enum/enum.module.ts b/projects/ng-helpers/src/pipes/enum/enum.module.ts new file mode 100644 index 0000000..4ad04f0 --- /dev/null +++ b/projects/ng-helpers/src/pipes/enum/enum.module.ts @@ -0,0 +1,16 @@ +import {CommonModule} from '@angular/common'; +import {NgModule} from '@angular/core'; +import {EnumPipe} from './enum.pipe'; + +@NgModule({ + imports: [ + CommonModule + ], + declarations: [ + EnumPipe + ], + exports: [ + EnumPipe + ] +}) +export class EnumModule { } diff --git a/projects/ng-helpers/src/pipes/enum/enum.pipe.spec.ts b/projects/ng-helpers/src/pipes/enum/enum.pipe.spec.ts new file mode 100644 index 0000000..5d5ea4c --- /dev/null +++ b/projects/ng-helpers/src/pipes/enum/enum.pipe.spec.ts @@ -0,0 +1,8 @@ +import { EnumPipe } from './enum.pipe'; + +describe('EnumPipe', () => { + it('create an instance', () => { + const pipe = new EnumPipe(); + expect(pipe).toBeTruthy(); + }); +}); diff --git a/projects/ng-helpers/src/pipes/enum/enum.pipe.ts b/projects/ng-helpers/src/pipes/enum/enum.pipe.ts new file mode 100644 index 0000000..1ddb533 --- /dev/null +++ b/projects/ng-helpers/src/pipes/enum/enum.pipe.ts @@ -0,0 +1,12 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'enum' +}) +export class EnumPipe implements PipeTransform { + + transform(value: any, args?: any): any { + return null; + } + +} diff --git a/projects/ng-helpers/src/pipes/sanitize/sanitize.module.spec.ts b/projects/ng-helpers/src/pipes/sanitize/sanitize.module.spec.ts new file mode 100644 index 0000000..001bfb8 --- /dev/null +++ b/projects/ng-helpers/src/pipes/sanitize/sanitize.module.spec.ts @@ -0,0 +1,13 @@ +import { SanitizeModule } from './sanitize.module'; + +describe('SanitizeModule', () => { + let sanitizeModule: SanitizeModule; + + beforeEach(() => { + sanitizeModule = new SanitizeModule(); + }); + + it('should create an instance', () => { + expect(sanitizeModule).toBeTruthy(); + }); +}); diff --git a/projects/ng-helpers/src/pipes/sanitize/sanitize.module.ts b/projects/ng-helpers/src/pipes/sanitize/sanitize.module.ts new file mode 100644 index 0000000..8f942bf --- /dev/null +++ b/projects/ng-helpers/src/pipes/sanitize/sanitize.module.ts @@ -0,0 +1,16 @@ +import {CommonModule} from '@angular/common'; +import {NgModule} from '@angular/core'; +import {SanitizePipe} from './sanitize.pipe'; + +@NgModule({ + imports: [ + CommonModule + ], + declarations: [ + SanitizePipe + ], + exports: [ + SanitizePipe + ] +}) +export class SanitizeModule { } diff --git a/projects/ng-helpers/src/pipes/sanitize/sanitize.pipe.spec.ts b/projects/ng-helpers/src/pipes/sanitize/sanitize.pipe.spec.ts new file mode 100644 index 0000000..0857538 --- /dev/null +++ b/projects/ng-helpers/src/pipes/sanitize/sanitize.pipe.spec.ts @@ -0,0 +1,8 @@ +import { SanitizePipe } from './sanitize.pipe'; + +describe('SanitizePipe', () => { + it('create an instance', () => { + const pipe = new SanitizePipe(); + expect(pipe).toBeTruthy(); + }); +}); diff --git a/projects/ng-helpers/src/pipes/sanitize/sanitize.pipe.ts b/projects/ng-helpers/src/pipes/sanitize/sanitize.pipe.ts new file mode 100644 index 0000000..40cc20c --- /dev/null +++ b/projects/ng-helpers/src/pipes/sanitize/sanitize.pipe.ts @@ -0,0 +1,12 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'sanitize' +}) +export class SanitizePipe implements PipeTransform { + + transform(value: any, args?: any): any { + return null; + } + +} diff --git a/projects/ng-helpers/tslint.json b/projects/ng-helpers/tslint.json index 73f120b..9257e27 100644 --- a/projects/ng-helpers/tslint.json +++ b/projects/ng-helpers/tslint.json @@ -4,13 +4,13 @@ "directive-selector": [ true, "attribute", - "lib", + "jp", "camelCase" ], "component-selector": [ true, "element", - "lib", + "jp", "kebab-case" ] }