Skip to content

Instantly share code, notes, and snippets.

View MTyson's full-sized avatar
💭
that IS a smile

Matt Tyson MTyson

💭
that IS a smile
View GitHub Profile
@MTyson
MTyson / jsfp.js
Created March 11, 2019 19:25
JS FP
var numbers = [10, 15, 20, 22, 23];
numbers = numbers.filter(function(x) { return (x % 2) == 0 });
console.info(numbers);
@MTyson
MTyson / song-effect.ts
Created February 25, 2019 20:56
Song Effect
@Injectable() export class SongEffects {
@Effect() update$: Observable<Action> = this.action$
.ofType(songs.LOAD_SONGS) 
.switchMap(() => this.songService 
.getRates() 
.map(data => new SongsAreLoadedAction(data))
);
constructor( private currencyService: SongService, private action$: Actions ) {}
}
@MTyson
MTyson / song-reducer.ts
Created February 25, 2019 20:54
Simple Song Reducer
export function songReducer(state = initialState, action: Action) {
switch(action.type) {
case 'DELETE_SONG': const songId = action.payload;
return state.filter(id => id !== songId);
default: return state;
}
}
@MTyson
MTyson / song-action.ts
Created February 25, 2019 20:52
Simple Song Action
import { Number } from './../models/song';
import { Action } from '@ngrx/store';
export const LOADSONGS = '[Song] LoadAll';
export const SONGDELETED = '[Song] Delete';
export class LoadSongAction implements Action {
type = LOAD_SONGS;
}
export class DeleteSongAction implements Action {
type = SONG_DELETED;
@MTyson
MTyson / song-component.ts
Last active February 25, 2019 20:48
SongComponent
import { LoadSongsAction } from './actions/songs'; 
import { Store } from '@ngrx/store';
import * as fromRoot from './reducers'; // The convention is to define fromRoot as our namespace for reducers import { Observable } from 'rxjs/Observable';
@Component({ selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush
})