Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(Guards): Re-implement guards feature to use services #81

Merged
merged 1 commit into from
May 3, 2016

Conversation

MikeRyanDev
Copy link
Member

Before we used provideGuard to quickly create guard factory functions. In order to play better with the offline compiler, this changes guards to instead use traditional services.

BREAKING CHANGE:

Before:

  const auth = provideGuard(function(http: Http) {

    return function(route: Route, params: any, isTerminal: boolean): Observable<boolean> {
      return http.get('/auth')
        .map(() => true)
        .catch(() => Observable.of(false));
    };

  }, [ Http ]);

After:

  @Injectable()
  export class AuthGuard implements Guard {
    constructor(private http: Http) { }

    protectRoute({ route, params, isTerminal }: TraversalCandidate): Observable<boolean> {
      return this.http.get('/auth')
        .map(() => true)
        .catch(() => Observable.of(false));
    }
  }

@MikeRyanDev MikeRyanDev force-pushed the refactor/change-guards-to-services branch 2 times, most recently from 40aee00 to db1a2bf Compare May 3, 2016 03:36
Before we used `provideGuard` to quickly create guard factory functions. In order to play better with the offline compiler, this changes guards to instead use traditional services.

BREAKING CHANGE:

  Before:

  ```ts
  const auth = provideGuard(function(http: Http) {

    return function(route: Route, params: any, isTerminal: boolean): Observable<boolean> {
      return http.get('/auth')
        .map(() => true)
        .catch(() => Observable.of(false));
    };

  }, [ Http ]);
  ```

  After:

  ```ts
  @Injectable()
  export class AuthGuard implements Guard {
    constructor(private http: Http) { }

    protectRoute({ route, params, isTerminal }: TraversalCandidate): Observable<boolean> {
      return this.http.get('/auth')
        .map(() => true)
        .catch(() => Observable.of(false));
    }
  }
  ```
@MikeRyanDev MikeRyanDev force-pushed the refactor/change-guards-to-services branch from db1a2bf to 8be45bf Compare May 3, 2016 03:37
@brandonroberts
Copy link
Member

LGTM

@brandonroberts brandonroberts merged commit 145b671 into ngconf May 3, 2016
@MikeRyanDev MikeRyanDev deleted the refactor/change-guards-to-services branch May 3, 2016 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants