Created
April 23, 2016 22:16
-
-
Save laurelnaiad/2c23fad55788e5ded72c58ee9292af1b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as memoize from 'memoize' | |
import { Observable } from 'rxjs/Observable' | |
import 'rxjs/add/operator/share' | |
import 'rxjs/add/operator/distinctUntilChanged' | |
export interface Selector<T,V> { | |
( source$: Observable<T> ): Observable<V> | |
} | |
export interface SelectorFactory<T,V> { | |
( ...args: any[] ): Selector<T,V> | |
} | |
export function publishDistinct<T,V>( | |
source$: Observable<T>, | |
selectorFactory: SelectorFactory<T,V> | |
): (...args: any[]) => Observable<V> { | |
return memoize( | |
( ...args: any[] ) => selectorFactory( ...args )( source$ ) | |
.distinctUntilChanged() | |
.share() | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment