Last active
May 28, 2018 01:35
-
-
Save zbarbuto/0b16e05111d5a7e9ab09aad225c21281 to your computer and use it in GitHub Desktop.
Developer function list
This file contains hidden or 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
@Component({ | |
template: ` | |
<div *ngFor="let component of components"> | |
<h4>{{ component.name }}</h4> | |
<button | |
*ngFor="let devFun of component.developerFunctions" | |
(click)="callMethod(component.componentInstance, devFun)"> | |
{{ devFun.name }} | |
</button> | |
</div> | |
`, | |
selector: 'developer-function-list', | |
}) | |
export class DeveloperFunctionList { | |
components = this.probeForComponents(); | |
public callMethod(componentInstance: any, devFun: any) { | |
componentInstance[devFun.name](); | |
} | |
probeForComponents() { | |
const components = getComponents(); // Recurse through dom for components using ng.probe - ommitted for berevity | |
return components | |
.filter(comp => !!comp.componentInstance) | |
.map(component => { | |
const developerFunctions = Reflect.getMetadata(comp.componentInstance.constructor, 'DEVELOPER_FUNCTIONS`); | |
return { | |
component, | |
developerFunctions | |
}; | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment