Skip to content
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

Merged
merged 8 commits into from
Apr 5, 2019
Merged

Add mapWithCaching #3

merged 8 commits into from
Apr 5, 2019

Conversation

kirahowe
Copy link
Collaborator

@kirahowe kirahowe commented Apr 3, 2019

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.

@coveralls
Copy link

coveralls commented Apr 3, 2019

Pull Request Test Coverage Report for Build 34

  • 14 of 14 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 19: 0.0%
Covered Lines: 51
Relevant Lines: 51

💛 - Coveralls

Copy link
Member

@ersimont ersimont left a 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).

projects/s-rxjs-utils/src/lib/map-with-caching.spec.ts Outdated Show resolved Hide resolved
projects/s-rxjs-utils/src/lib/map-with-caching.spec.ts Outdated Show resolved Hide resolved
projects/s-rxjs-utils/src/lib/map-with-caching.spec.ts Outdated Show resolved Hide resolved
projects/s-rxjs-utils/src/lib/map-with-caching.ts Outdated Show resolved Hide resolved
projects/s-rxjs-utils/src/lib/map-with-caching.ts Outdated Show resolved Hide resolved
projects/s-rxjs-utils/src/lib/map-with-caching.ts Outdated Show resolved Hide resolved
Co-Authored-By: kiramclean <kiramclean@users.noreply.github.com>
* @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
Copy link
Member

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.
Copy link
Member

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 ..."

@ersimont ersimont merged commit ebf81b1 into master Apr 5, 2019
@ersimont ersimont deleted the map-array-with-caching branch April 5, 2019 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants