-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add mapWithCaching #3
Conversation
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.
[red]
You should add this function to the (very very crude) integration test by importing and using it in app.component.ts
. That will then show you this needs to be added to public_api.ts
.
[yellow]
We should think about and document what happens when 2 elements in the same array have the same cache key (particularly when the rest of the object might be different).
Co-Authored-By: kiramclean <kiramclean@users.noreply.github.com>
…s-rxjs-utils into map-array-with-caching
* @param buildCacheKey A function that converts an upstream object into a string to use as the cache key. Needs to return a unique key for each item in the source array. | ||
* @param buildDownstreamItem A function that converts an upstream object into a downstream object | ||
* @param buildDownstreamItem |
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.
[green]
You can remove the entire line. TSDoc and editors will still display the type info for it.
@@ -4,11 +4,13 @@ import { map } from "rxjs/operators"; | |||
/** | |||
* Applies a given function to each item in the upstream array and emits the result. Each item is then cached using the key generated by `buildCacheKey` so that the next emission contains references to the matching objects from previous emission, without running `buildDownstreamItem` again. The cache is only held between successive emissions. |
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.
[yellow]
There was a sneaky comment hiding under my suggested rewording here from the last round of review:
It would also be nice to also include a sentence "This is useful e.g. when ..."
This adds
mapWithCaching
that maps each object in an array using the given function, returning a reference to the same object if it was in the array last time the observable emitted.