Skip to content

Commit

Permalink
fix: make sure dwelling does not emit the last events on completion
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinRoy committed Feb 28, 2018
1 parent e29d969 commit 149e26b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/move/dwelling.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import longMoves from './long-move';
* as a dwell.
* @param {number} [movementsThreshold=0] - The threshold below which movements are considered
* static.
* @param {Scheduler} [scheduler] - The scheduler to use for managing the timers that handle the timeout
* for each value
* @return {Observable} An observable on dwellings in the movement.
*/
export default (drag$, delay, movementsThreshold = 0) =>
Observable.merge(drag$.take(1), longMoves(drag$, movementsThreshold))
// Emit after a pause in the movements.
.debounceTime(delay)
export default (drag$, delay, movementsThreshold = 0, scheduler) =>
Observable.merge(drag$.first(), longMoves(drag$, movementsThreshold))
// Emit when no long movements happend for delay time.
.debounceTime(delay, scheduler)
// debounceTime emits the last item when the source observable completes.
// We don't want that here so we only take until drag is done.
.takeUntil(drag$.last())
// Make sure we do emit the last position.
.withLatestFrom(drag$)
.map(([, last]) => last);
.withLatestFrom(drag$, (_, last) => last);

0 comments on commit 149e26b

Please sign in to comment.