Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ngx-utils): ngx-utils module replace ngx-pipes
- Loading branch information
Showing
45 changed files
with
791 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Params, RouterStateSnapshot } from '@angular/router'; | ||
import { NgxsModule } from '@ngxs/store'; | ||
import { NgxsRouterPluginModule, RouterStateSerializer } from '@ngxs/router-plugin'; | ||
|
||
export interface RouterStateParams { | ||
url: string; | ||
params: Params; | ||
queryParams: Params; | ||
} | ||
|
||
// Map the router snapshot to { url, params, queryParams } | ||
export class CustomRouterStateSerializer implements RouterStateSerializer<RouterStateParams> { | ||
serialize(routerState: RouterStateSnapshot): RouterStateParams { | ||
const { | ||
url, | ||
root: { queryParams }, | ||
} = routerState; | ||
let { root: route } = routerState; | ||
while (route.firstChild) { | ||
route = route.firstChild; | ||
} | ||
const { params } = route; | ||
return { url, params, queryParams }; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ngx-utils | ||
========= | ||
|
||
same as `@ngrx-utils/store` without dependency on `@ngrx/store` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
name: 'ngx-utils', | ||
preset: '../../jest.config.js', | ||
coverageDirectory: '../../coverage/libs/ngx-utils' | ||
}; |
2 changes: 1 addition & 1 deletion
2
libs/ngx-pipes/ng-package.prod.json → libs/ngx-utils/ng-package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "ngx-utils", | ||
"version": "0.0.1", | ||
"peerDependencies": { | ||
"@angular/common": "^7.0.0", | ||
"@angular/core": "^7.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// export * from './lib/decorators/index'; | ||
export * from './lib/directives/index'; | ||
export * from './lib/operators/index'; | ||
export * from './lib/pipes/index'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './ng-let/ng-let.module'; | ||
export * from './router-link-match/router-link-match.module'; |
119 changes: 119 additions & 0 deletions
119
libs/ngx-utils/src/lib/directives/ng-let/ng-let.directive.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { CommonModule } from '@angular/common'; | ||
import { Component, NgModule, ViewChild } from '@angular/core'; | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { By } from '@angular/platform-browser'; | ||
import { Observable, of } from 'rxjs'; | ||
import { NgLetDirective } from './ng-let.directive'; | ||
import { NgLetModule } from './ng-let.module'; | ||
|
||
@Component({ | ||
template: '', | ||
selector: 'sand-test' | ||
}) | ||
class TestComponent { | ||
@ViewChild(NgLetDirective) ngLetDirective: NgLetDirective; | ||
test$: Observable<number>; | ||
test = 10; | ||
nestedTest = 20; | ||
functionTest = (a: number, b: number) => a + b; | ||
} | ||
|
||
@NgModule({ | ||
declarations: [TestComponent], | ||
imports: [NgLetModule, CommonModule], | ||
exports: [NgLetModule, TestComponent] | ||
}) | ||
class TestModule {} | ||
|
||
describe('ngLet directive', () => { | ||
let fixture: ComponentFixture<TestComponent>; | ||
function getComponent(): TestComponent { | ||
return fixture.componentInstance; | ||
} | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [TestModule] | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
fixture = null!; | ||
}); | ||
|
||
it('should create NgLetModule', () => { | ||
expect(new NgLetModule()).toBeTruthy(); | ||
}); | ||
|
||
it('should work in a template attribute', async(() => { | ||
const template = '<span *ngLet="test as i">hello{{ i }}</span>'; | ||
fixture = createTestComponent(template); | ||
getComponent().test = 7; | ||
fixture.detectChanges(); | ||
expect(fixture.debugElement.queryAll(By.css('span')).length).toEqual(1); | ||
expect(fixture.nativeElement.textContent).toBe('hello7'); | ||
})); | ||
|
||
it('should work on a template element', async(() => { | ||
const template = '<ng-template [ngLet]="test" let-i>hello{{ i }}</ng-template>'; | ||
fixture = createTestComponent(template); | ||
getComponent().test = 5; | ||
fixture.detectChanges(); | ||
expect(fixture.nativeElement.textContent).toBe('hello5'); | ||
})); | ||
|
||
it('should handle nested ngLet correctly', async(() => { | ||
const template = | ||
'<div *ngLet="test as i"><span *ngLet="nestedTest as k">hello{{ i + k }}</span></div>'; | ||
|
||
fixture = createTestComponent(template); | ||
|
||
getComponent().test = 3; | ||
getComponent().nestedTest = 5; | ||
fixture.detectChanges(); | ||
expect(fixture.debugElement.queryAll(By.css('span')).length).toEqual(1); | ||
expect(fixture.nativeElement.textContent).toBe('hello8'); | ||
})); | ||
|
||
it('should update several nodes', async(() => { | ||
const template = | ||
'<span *ngLet="test + 1; let i">helloNumber{{ i }}</span>' + | ||
'<span *ngLet="functionTest(5, 8) as j">helloFunction{{ j }}</span>'; | ||
|
||
fixture = createTestComponent(template); | ||
|
||
getComponent().test = 4; | ||
fixture.detectChanges(); | ||
expect(fixture.debugElement.queryAll(By.css('span')).length).toEqual(2); | ||
expect(fixture.nativeElement.textContent).toContain('helloNumber5helloFunction13'); | ||
})); | ||
|
||
it('should work on async pipe', async(() => { | ||
const template = '<span *ngLet="test$ | async as t">helloAsync{{ t }}</span>'; | ||
|
||
fixture = createTestComponent(template); | ||
|
||
getComponent().test$ = of(15); | ||
fixture.detectChanges(); | ||
expect(fixture.debugElement.queryAll(By.css('span')).length).toEqual(1); | ||
expect(fixture.nativeElement.textContent).toContain('helloAsync15'); | ||
})); | ||
|
||
it('should accept input', async(() => { | ||
const template = '<span *ngLet="test as i">hello{{ i }}</span>'; | ||
|
||
fixture = createTestComponent(template); | ||
fixture.detectChanges(); | ||
|
||
expect(getComponent().ngLetDirective).toBeTruthy(); | ||
getComponent().ngLetDirective.ngLet = 21; | ||
fixture.detectChanges(); | ||
expect(fixture.nativeElement.textContent).toContain('hello21'); | ||
})); | ||
}); | ||
|
||
function createTestComponent(template: string): ComponentFixture<TestComponent> { | ||
return TestBed.overrideComponent(TestComponent, { set: { template } }).createComponent( | ||
TestComponent | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { NgLetDirective } from './ng-let.directive'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule | ||
], | ||
declarations: [NgLetDirective], | ||
exports: [NgLetDirective] | ||
}) | ||
export class NgLetModule { } |
Oops, something went wrong.