-
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
fix(windowCount): set default value for skip argument, do not emit em… #273
Changes from all commits
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 |
---|---|---|
|
@@ -25,29 +25,34 @@ class WindowCountOperator<T, R> implements Operator<T, R> { | |
} | ||
|
||
class WindowCountSubscriber<T> extends Subscriber<T> { | ||
private windows: { count: number, window: Subject<T> } [] = []; | ||
private windows: { count: number, notified : boolean, window: Subject<T> } [] = [{ count: 0, notified : false, window : new Subject<T>() }]; | ||
private count: number = 0; | ||
|
||
constructor(destination: Observer<T>, private windowSize: number, private startWindowEvery: number) { | ||
super(destination); | ||
super(destination); | ||
} | ||
|
||
_next(value: T) { | ||
const count = (this.count += 1); | ||
const startWindowEvery = this.startWindowEvery; | ||
const startWindowEvery = (this.startWindowEvery > 0) ? this.startWindowEvery : this.windowSize; | ||
const windowSize = this.windowSize; | ||
const windows = this.windows; | ||
const len = windows.length; | ||
|
||
if (startWindowEvery && count % this.startWindowEvery === 0) { | ||
if (count % startWindowEvery === 0) { | ||
let window = new Subject<T>(); | ||
windows.push({ count: 0, window }); | ||
this.destination.next(window); | ||
windows.push({ count: 0, notified : false, window : window }); | ||
} | ||
|
||
const len = windows.length; | ||
for (let i = 0; i < len; i++) { | ||
let w = windows[i]; | ||
const window = w.window; | ||
|
||
if (!w.notified) { | ||
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. This flag is introduced to let window to be notified only if window will have any values to be contained, such as note : it seems current RxJS (Reactive-Extensions/RxJS#148) allows empty window being emitted at the end. 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. |
||
w.notified = true; | ||
this.destination.next(window); | ||
} | ||
|
||
window.next(value); | ||
if (windowSize === (w.count += 1)) { | ||
window.complete(); | ||
|
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.
As mentioned in #271 (comment), some function initialize default value to 0 and some sets it to
null
fornumber
types. As same as previous changes only updates value but not default value since not sure which one's recommended.