-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(lib): make sure all inputs chanegs are sent to new component
Also refactor ReflectService to simplify it and remove WindowRef related services
- Loading branch information
Showing
28 changed files
with
269 additions
and
246 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
2 changes: 1 addition & 1 deletion
2
...mponent-outlet-injector.directive.spec.ts → ...mponent-outlet-injector.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
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
68 changes: 68 additions & 0 deletions
68
...mponent/src/lib/component-injector/component-outlet/component-outlet-io.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,68 @@ | ||
/* eslint-disable @angular-eslint/component-selector */ | ||
import { Component, EventEmitter, Input, Output, Type } from '@angular/core'; | ||
import { TestSetup } from '../../../test'; | ||
import { ComponentOutletInjectorDirective } from './component-outlet-injector.directive'; | ||
import { ComponentOutletIoDirective } from './component-outlet-io.directive'; | ||
|
||
describe('Directive: ComponentOutletIo', () => { | ||
@Component({ selector: 'dynamic', template: 'DynamicComponent' }) | ||
class DynamicComponent { | ||
@Input() prop1: any; | ||
@Input() prop2: any; | ||
@Output() output = new EventEmitter<any>(); | ||
} | ||
|
||
@Component({ | ||
selector: 'host', | ||
template: `<ng-container *ngComponentOutlet="component"></ng-container>`, | ||
}) | ||
class HostComponent { | ||
component: Type<any>; | ||
} | ||
|
||
const testSetup = new TestSetup(HostComponent, { | ||
props: { component: DynamicComponent }, | ||
ngModule: { | ||
declarations: [ | ||
ComponentOutletIoDirective, | ||
ComponentOutletInjectorDirective, | ||
DynamicComponent, | ||
], | ||
}, | ||
}); | ||
|
||
describe('inputs with `NgComponentOutlet` * syntax', () => { | ||
it('should be passed to dynamic component instance', async () => { | ||
const inputs = { prop1: '123', prop2: 1 }; | ||
|
||
const fixture = await testSetup.redner<{ inputs: any }>({ | ||
props: { inputs }, | ||
template: `<ng-container *ngComponentOutlet="component; ndcDynamicInputs: inputs"></ng-container>`, | ||
}); | ||
|
||
expect(fixture.getComponent(DynamicComponent)).toEqual( | ||
expect.objectContaining({ | ||
prop1: '123', | ||
prop2: 1, | ||
}), | ||
); | ||
}); | ||
}); | ||
|
||
describe('outputs with `NgComponentOutlet` * syntax', () => { | ||
it('should be passed to dynamic component instance', async () => { | ||
const outputs = { output: jest.fn() }; | ||
|
||
const fixture = await testSetup.redner<{ outputs: any }>({ | ||
props: { outputs }, | ||
template: `<ng-container *ngComponentOutlet="component; ndcDynamicOutputs: outputs"></ng-container>`, | ||
}); | ||
|
||
expect(outputs.output).not.toHaveBeenCalled(); | ||
|
||
fixture.getComponent(DynamicComponent).output.emit('data'); | ||
|
||
expect(outputs.output).toHaveBeenCalledWith('data'); | ||
}); | ||
}); | ||
}); |
26 changes: 26 additions & 0 deletions
26
...ic-component/src/lib/component-injector/component-outlet/component-outlet-io.directive.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,26 @@ | ||
import { Directive, DoCheck, Input } from '@angular/core'; | ||
|
||
import { InputsType, IoService, OutputsType } from '../../io'; | ||
|
||
@Directive({ | ||
selector: | ||
// eslint-disable-next-line @angular-eslint/directive-selector | ||
'[ngComponentOutletNdcDynamicInputs],[ngComponentOutletNdcDynamicOutputs]', | ||
exportAs: 'ndcDynamicIo', | ||
providers: [IoService], | ||
}) | ||
export class ComponentOutletIoDirective implements DoCheck { | ||
@Input() | ||
ngComponentOutletNdcDynamicInputs: InputsType; | ||
@Input() | ||
ngComponentOutletNdcDynamicOutputs: OutputsType; | ||
|
||
constructor(private ioService: IoService) {} | ||
|
||
ngDoCheck() { | ||
this.ioService.update( | ||
this.ngComponentOutletNdcDynamicInputs, | ||
this.ngComponentOutletNdcDynamicOutputs, | ||
); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
projects/ng-dynamic-component/src/lib/component-injector/component-outlet/index.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,3 @@ | ||
export * from './component-outlet-io.directive'; | ||
export * from './component-outlet-injector.directive'; | ||
export * from './component-outlet-injector.module'; |
3 changes: 1 addition & 2 deletions
3
projects/ng-dynamic-component/src/lib/component-injector/index.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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export * from './token'; | ||
export * from './component-outlet-injector.directive'; | ||
export * from './component-outlet-injector.module'; | ||
export * from './component-outlet'; |
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
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
Oops, something went wrong.