Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian Troncone btroncone

View GitHub Profile
@btroncone
btroncone / subscription-cleanup.md
Last active Oct 7, 2020
Cleaning up subscriptions in Angular
View subscription-cleanup.md

Which do you prefer?

Adding to common sub, calling subscription.unsubscribe() in ngOnDestroy:

export class MyComponent {
  private _subscription: Subscription;
  
  ngOnInit() {
    this._subscription = myObservable
@btroncone
btroncone / service.spec.ts
Last active Sep 4, 2019
Angular service testing (constructor)
View service.spec.ts
import { inject, TestBed } from '@angular/core/testing';
import { of } from 'rxjs/observable/of';
import { LoggingService, LocalStorageService } from '../';
import { RouterEventService } from '../../routing';
export class MockLocalStorageService {
setItem() {}
getItem() { return []; }
}
export class MockRouterEventService {
@btroncone
btroncone / README.md
Created Mar 30, 2016
angular 2 basic counter
View README.md

angular 2 basic counter

Basic counter in Angular 2.

@btroncone
btroncone / README.md
Created Mar 30, 2016
@ngrx/store counter
View README.md

@ngrx/store counter

Basic counter w/ @ngrx/store.

@btroncone
btroncone / rxjs_operators_by_example.md
Last active Oct 20, 2020
RxJS 5 Operators By Example
View rxjs_operators_by_example.md
@btroncone
btroncone / ngrxintro.md
Last active Oct 27, 2020
A Comprehensive Introduction to @ngrx/store - Companion to Egghead.io Series
View ngrxintro.md

Comprehensive Introduction to @ngrx/store

By: @BTroncone

Also check out my lesson @ngrx/store in 10 minutes on egghead.io!

Update: Non-middleware examples have been updated to ngrx/store v2. More coming soon!

Table of Contents

@btroncone
btroncone / bootstrap.ts
Last active Jul 16, 2017
Basic demonstration of how NgRx middleware can be used to keep local storage in sync with user-defined state slices.
View bootstrap.ts
//specify what state slices you would like to keep synced with local storage
export function main() {
return bootstrap(TodoApp, [
provideStore(APP_REDUCERS),
localStorageMiddleware('todos', 'visibilityFilter')
])
.catch(err => console.error(err));
}
@btroncone
btroncone / todo-item.ts
Last active Feb 20, 2019
Ng2 Observable Todo-Service
View todo-item.ts
import {Component, Input, Output, EventEmitter} from "angular2/core";
import {Todo} from "../services/Todo-Service";
@Component({
selector: 'todo-item',
styles: [
`
.complete{
text-decoration: line-through;
}
@btroncone
btroncone / authentication.ts
Last active Mar 16, 2020
Angular 2 application role access decorator, wrapping built in CanAccess functionality. Prevents view transitions when user roles are not appropriate.
View authentication.ts
import { Injectable } from 'angular2/core';
import { Storage } from './storage';
import { CurrentUser } from '../interfaces/common';
@Injectable()
export class Authentication{
private _storageService : Storage;
private _userKey : string = "CURRENT_USER";
constructor(storageService : Storage){
You can’t perform that action at this time.