Skip to content

Instantly share code, notes, and snippets.

View MikeRyanDev's full-sized avatar

Mike Ryan MikeRyanDev

View GitHub Profile
export class BookEffects {
@Effect() getAllBooks$ = this.actions$.pipe(
ofType(INPUT_ACTION_TYPE),
exhaustMap(() => this.booksService.getAll()),
);
}
export class BookEffects {
@Effect() getAllBooks$ = this.actions$.pipe(
ofType(INPUT_ACTION_TYPE),
switchMap(() => this.booksService.getAll()),
);
}
import { _throw } from 'rxjs/observable/throw';
import { of } from 'rxjs/observable/of';
import { Actions } from '@ngrx/effects';
class MyEffects {
@Effect() doSomething$ = this.actions$
.ofType('SOMETHING')
.mergeMap(action => {
return this.http.post('/endpoint')
.mergeMap(result => {
import { Directive, Output, EventEmitter, ChangeDetectionStrategy, ElementRef } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import 'rxjs/add/operator/takeUntil';
@Directive({
selector: '[draggable]',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class DraggableDirective {

@ngrx/store v3

Problems:

  • Users want to compose reducer tree across modules
  • Idea of a single reducer function makes it difficult for the library to dynamically augment the shape of the state tree
  • Turning control over to the library to build the root reducer limits the use of meta-reducers
  • Feature modules may inadvertently collide with the state of the root module
  • Library authors may want to leverage @ngrx/store in their projects and provide an easy way
import { ApolloStore } from 'apollo-client';
import { Store } from '@ngrx/store';
import { skip } from 'rxjs/operator/skip';
import { take } from 'rxjs/operator/take';
export function toApolloStore(store: Store<any>): ApolloStore {
return {
subscribe(fn: () => void): () => void {
const futureStates$ = skip.call(store, 1);
import 'rxjs/add/observable/of';
import { Observable } from 'rxjs/Observable';
const mockRestService = {
get: jasmine.createSpy('get').and.returnValue(Observable.of({
}))
}
@MikeRyanDev
MikeRyanDev / reselect.ts
Created August 24, 2016 12:46
ngrx/store reselect
import { defaultMemoize as memoize } from 'reselect';
export interface StreamSelector<A,B> {
(input$: Observable<T>): Observable<R>;
}
export interface Share {
<A,B>(): StreamSelector<A,B>;
<A,B,C>(c: C): StreamSelector<A,B>;
<A,B,C,D>(c: C, d: D): StreamSelector<A,B>;
import 'rxjs/add/observable/of';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Book } from '../models/book';
@Injectable()
export class BooksService {
getBooks(): Observable<Book[]> {
return Observable.of([
import { Component } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Book } from './models/book';
import { BooksService } from './services/books-service';
@Component({
selector: 'books-app',
template: `
<books-header></books-header>
<book-card