Skip to content

Instantly share code, notes, and snippets.

Avatar

John Crowson jtcrowson

View GitHub Profile
@jtcrowson
jtcrowson / auth-guard.service.spec.ts
Created Mar 7, 2019
auth-guard.service.spec.ts from version 7.3.0 of ngrx/platform
View auth-guard.service.spec.ts
// NgRx v7.3.0
describe('Auth Guard', () => {
let guard: AuthGuard;
let store: Store<any>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({
...fromRoot.reducers,
@jtcrowson
jtcrowson / auth-guard.service.ts
Created Mar 7, 2019
auth-guard.service.ts from version 7.3.0 of ngrx/platform
View auth-guard.service.ts
// NgRx v7.3.0
@Injectable({
providedIn: 'root',
})
export class AuthGuard implements CanActivate {
constructor(private store: Store<fromAuth.State>) {}
canActivate(): Observable<boolean> {
return this.store.pipe(
select(fromAuth.getLoggedIn),
View dialog-overview-example.ts
import { Component } from '@angular/core';
import { MatDialog } from '@angular/material';
@Component({
selector: 'dialog-overview-example',
template: `<a (click)="openDialog()">Open Dialog</a>`
})
export class DialogOverviewExample {
constructor(public dialog: MatDialog) {}
View ngrx-step2.ts
// -- error.actions.ts --
export class LaunchErrorModal implements Action {
readonly type = ErrorActions.LaunchErrorModal;
}
export class MarkErrorModalAsOpen implements Action {
readonly type = ErrorActions.MarkErrorModalAsOpen;
}
export class CloseErrorModal implements Action {
View ngrx-step1.ts
// -- error.actions.ts --
export class LaunchErrorModal implements Action {
readonly type = ErrorActions.LaunchErrorModal;
}
// -- error.effects.ts --
@Effect({ dispatch: false })
launchErrorModal$: Observable<Action> = this.actions$.pipe(
ofType<LaunchErrorModal>(ErrorActions.LaunchErrorModal),
tap(() => this.dialog.open(ErrorModalComponent))