Skip to content

Instantly share code, notes, and snippets.

@MikeRyanDev
Created February 25, 2018 21:16
Show Gist options
  • Save MikeRyanDev/3939d6ad0729bc3f8db1b4fb692033cf to your computer and use it in GitHub Desktop.
Save MikeRyanDev/3939d6ad0729bc3f8db1b4fb692033cf to your computer and use it in GitHub Desktop.
groupBy(
/**
* Select groups by their `bookId`
*/
action => action.bookId,
/**
* Map each action to the `bookId` for convenience
*/
action => action.bookId,
/**
* The duration selector lets us create an observable that
* instructs `groupBy` when to dispose of a group. It will
* be disposed when either the returned observable emits a
* a value or completes
*/
bookId$ => bookId$.pipe(
/**
* The `timeoutWith` operator lets you time out an observable
* after a set amount of time and then falls back to the
* provided observable.
*
* Here we want to timeout after 15s and then fall back to
* no behavior
*/
timeoutWith(15000, Observable.empty()),
/**
* When telling `groupBy` when to end we don't want it
* to dispose of the group when the group has a new action
* so we simply have it ignore all actions, instead waiting
* to dispose the group when it times out
*/
ignoreElements(),
),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment