Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. export interface IApprove {
  2. approve():boolean;
  3. }
  4.  
  5. export class FirstImplementation implements IApprove {
  6. approve():boolean {
  7. return true;
  8. }
  9. }
  10.  
  11. export class SecondImplementation implements IApprove {
  12. private data:number;
  13.  
  14. approve():boolean {
  15. return this.data > 1;
  16. }
  17. }
  18.  
  19. function approve(guardsClasses:Array<any>, data:number):boolean {
  20. guardsClaases.forEach((guardClass) => {
  21. let guard = injector.get(guardClass); // this is some abstract injector that create instance from class
  22. // here I would like to check whether guard instance have "data" variable. If so - pass data value.
  23. let result = guard.approve();
  24. if (!result) {
  25. return false
  26. }
  27. });
  28. return true;
  29. }
  30.  
  31. approve([FirstImplementation, SecondImplementation], 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement