-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(publishReplay): add selector function to publishReplay #2885
Changes from 1 commit
6d1742e
6daa0a6
a0182ce
684ec1e
2a157ef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -409,4 +409,15 @@ describe('Observable.prototype.publishReplay', () => { | |
|
||
published.connect(); | ||
}); | ||
|
||
it('should mirror a simple source Observable with selector', () => { | ||
const selector = observable => observable.map(v => String.fromCharCode(96 + parseInt(v))); | ||
const source = cold('--1-2---3-4---|'); | ||
const sourceSubs = '^ !'; | ||
const published = source.publishReplay(1, Number.POSITIVE_INFINITY, selector); | ||
const expected = '--a-b---c-d---|'; | ||
|
||
expectObservable(published).toBe(expected); | ||
expectSubscriptions(source.subscriptions).toBe(sourceSubs); | ||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to add tests for:
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -6,13 +6,15 @@ import { publishReplay as higherOrder } from '../operators'; | |||||||
/** | ||||||||
* @param bufferSize | ||||||||
* @param windowTime | ||||||||
* @param selector | ||||||||
* @param scheduler | ||||||||
* @return {ConnectableObservable<T>} | ||||||||
* @method publishReplay | ||||||||
* @owner Observable | ||||||||
*/ | ||||||||
export function publishReplay<T>(this: Observable<T>, bufferSize: number = Number.POSITIVE_INFINITY, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like below, we'll need to add some function overloads for TypeScript users to keep this change from being breaking. Here's what the Lines 7 to 9 in accbcd0
|
||||||||
windowTime: number = Number.POSITIVE_INFINITY, | ||||||||
selector?: (source: Observable<T>) => Observable<T>, | ||||||||
scheduler?: IScheduler): ConnectableObservable<T> { | ||||||||
return higherOrder(bufferSize, windowTime, scheduler)(this); | ||||||||
return higherOrder(bufferSize, windowTime, selector, scheduler)(this); | ||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -7,6 +7,8 @@ import { UnaryFunction } from '../interfaces'; | |||||||
|
||||||||
export function publishReplay<T>(bufferSize: number = Number.POSITIVE_INFINITY, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'll need some function signature overloads for this so we don't break compatability for people expecting See what Lines 6 to 8 in accbcd0
|
||||||||
windowTime: number = Number.POSITIVE_INFINITY, | ||||||||
selector: (source: Observable<T>) => Observable<T>, | ||||||||
scheduler?: IScheduler): UnaryFunction<Observable<T>, ConnectableObservable<T>> { | ||||||||
return (source: Observable<T>) => multicast(new ReplaySubject<T>(bufferSize, windowTime, scheduler))(source) as ConnectableObservable<T>; | ||||||||
const subject = new ReplaySubject<T>(bufferSize, windowTime, scheduler); | ||||||||
return (source: Observable<T>) => multicast(() => subject, selector)(source) as ConnectableObservable<T>; | ||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one is a little too clever. :)
Can you use something more straightforward? A hash lookup or something?