2016-04-08 23 views
5

Acemi soru: ngrx kullanarak bir angular2 uygulamasına sahibim, bir öğeye durumu (gözlenebilir dizi) döndüren bir hizmetim var.Durumu filtrelemeli?

Sorum, bileşende kullanılacak salt okunur bir alt kümesini istiyorsam durumu filtreleyebilir miyim?

Redüktör, servis veya bileşende mi yaparım?

cevap

2

Bazı yönergelikler ngrx example application'da bulunabilir. Orada seçiciler alongside reducers tanımlandığı gibi olduğu bir kalıptır:

/** 
* Because the data structure is defined within the reducer it is optimal to 
* locate our selector functions at this level. If store is to be thought of 
* as a database, and reducers the tables, selectors can be considered the 
* queries into said database. Remember to keep your selectors small and 
* focused so they can be combined and composed to fit each particular 
* use-case. 
*/ 
export function getBookEntities() { 
    return (state$: Observable<BooksState>) => state$ 
    .select(s => s.entities); 
}; 

ve bu seçiciler durum filtre/seçmek için used in (smart) components şunlardır:

... 
export class CollectionPage { 

    books$: Observable<BooksInput>; 

    constructor(store: Store<AppState>) { 
    this.books$ = store.let(getBookCollection()); 
    } 
} 
Bu model/mekanizması durumunu filtre kullanılabilir

ya Bileşenler veya hizmetler - mimarinize en uygun olanı seçin.

+0

Tamam, açıklama için teşekkürler – user3253156