Skip to content

Instantly share code, notes, and snippets.

@laurelnaiad
Created April 23, 2016 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laurelnaiad/2c23fad55788e5ded72c58ee9292af1b to your computer and use it in GitHub Desktop.
Save laurelnaiad/2c23fad55788e5ded72c58ee9292af1b to your computer and use it in GitHub Desktop.
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