-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(outputs): add ability to pass template variables to outputs
closes #331
- Loading branch information
Showing
8 changed files
with
208 additions
and
16 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 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
10 changes: 10 additions & 0 deletions
10
projects/ng-dynamic-component/src/lib/io/event-argument.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,10 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
|
||
export function defaultEventArgumentFactory() { | ||
return '$event'; | ||
} | ||
|
||
export const EventArgumentToken = new InjectionToken<string>('EventArgument', { | ||
providedIn: 'root', | ||
factory: defaultEventArgumentFactory, | ||
}); |
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,2 +1,4 @@ | ||
export * from './types'; | ||
export * from './event-argument'; | ||
export * from './io.service'; | ||
export * from './io-factory.service'; |
6 changes: 5 additions & 1 deletion
6
projects/ng-dynamic-component/src/lib/io/io-factory.service.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,19 +1,23 @@ | ||
import { | ||
ComponentFactoryResolver, | ||
Inject, | ||
Injectable, | ||
KeyValueDiffers, | ||
} from '@angular/core'; | ||
|
||
import { EventArgumentToken } from './event-argument'; | ||
import { IoService } from './io.service'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class IoFactoryService { | ||
constructor( | ||
private differs: KeyValueDiffers, | ||
private cfr: ComponentFactoryResolver, | ||
@Inject(EventArgumentToken) | ||
private eventArgument: unknown, | ||
) {} | ||
|
||
create() { | ||
return new IoService(this.differs, this.cfr); | ||
return new IoService(this.differs, this.cfr, this.eventArgument); | ||
} | ||
} |
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,17 @@ | ||
export interface InputsType { | ||
[k: string]: any; | ||
} | ||
export interface OutputsType { | ||
[k: string]: OutputExpression | undefined; | ||
} | ||
|
||
export interface OutputWithArgs { | ||
handler: AnyFunction; | ||
args?: any[]; | ||
} | ||
|
||
export type OutputExpression = EventHandler | OutputWithArgs; | ||
|
||
export type EventHandler<T = any> = (event: T) => any; | ||
|
||
export type AnyFunction = (...args: any[]) => any; |
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