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 'cloneData' option to buildMemoryStorage #581

Merged
merged 18 commits into from
Jul 1, 2023

Conversation

bhallionOhbibi
Copy link
Contributor

See issue 580 for more details

@codecov
Copy link

codecov bot commented Jun 28, 2023

Codecov Report

Merging #581 (2e2f9cd) into main (c91e6a0) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main      #581   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines          576       578    +2     
  Branches       188       190    +2     
=========================================
+ Hits           576       578    +2     
Impacted Files Coverage Δ
src/storage/memory.ts 100.00% <100.00%> (ø)

@bhallionOhbibi
Copy link
Contributor Author

Looks like there is some issue with the CI

src/storage/memory.ts Outdated Show resolved Hide resolved
src/storage/memory.ts Outdated Show resolved Hide resolved
src/storage/memory.ts Outdated Show resolved Hide resolved
src/storage/memory.ts Outdated Show resolved Hide resolved
test/storage/memory.test.ts Outdated Show resolved Hide resolved
src/storage/memory.ts Outdated Show resolved Hide resolved
test/storage/memory.test.ts Show resolved Hide resolved
src/storage/memory.ts Outdated Show resolved Hide resolved
@arthurfiorette
Copy link
Owner

The CI failed because of linting, please run pnpm lint -- --fix and pnpm format before push to lint your code.

@arthurfiorette
Copy link
Owner

I added a review to update the cloneData property instead of creating a new one. Overall, suuper thanks for your time in this PR :)

@bhallionOhbibi
Copy link
Contributor Author

Thanks for your review. This is the first time writing typescript code. As yo ucan expect, my local configuration is not exactly mature right now 😅

I updated the test, but I'm not sure if this is enough, please let me know what you think.

About storeClone:
I removed it. It was an attempt to be a bit more explicit, as I find 'double' on cloneData less explicit. In the other hand, 'double' on cloneData limit amount of parameters and allow us to use the new option without adding cleanupInterval and maxEntries to false every time.
You decide what's best for this library and adding 'double' to cloneData seems like a fine typescript way of adding functionnality.

Another note about this whole clone thing. I really think that the double options should be the default value. I would argue that anyone trying this library for the first time might have a hard time understanding why their axios.get calls doesnt returns the same data every time. And suddenly having to check for cached property or having to provide additionnal configuration might block some users from using the library altogether.

@bhallionOhbibi bhallionOhbibi changed the title Add 'storeClone' option to buildMemoryStorage function Add 'cloneData' option to buildMemoryStorage Jun 29, 2023
test/storage/memory.test.ts Outdated Show resolved Hide resolved
src/storage/memory.ts Outdated Show resolved Hide resolved
test/storage/memory.test.ts Outdated Show resolved Hide resolved
@arthurfiorette
Copy link
Owner

adding 'double' to cloneData seems like a fine typescript way

Yeah! I'm just not satisfied enough with the double name, any synonyms comes to your mind?

I really think that the double options should be the default value.

They may be, but i'd only make them default on the next major version as it will be a breaking change... Also, I'm not sure how the GC will behave on data being cloned everywhere.

bhallionOhbibi and others added 3 commits June 30, 2023 12:18
Add this comment to code coverage skip the structuredClone test

Co-authored-by: Arthur Fiorette <github@arthur.place>
Co-authored-by: Arthur Fiorette <github@arthur.place>
@bhallionOhbibi
Copy link
Contributor Author

bhallionOhbibi commented Jun 30, 2023

Instead of double I suggested all.

But it would be more explicit and also more configurable to use an enum.
Perhaps something like:

  • onSet
  • onGet

Where the user can specify one, both or none of the options (so an array of string maybe ?).
I think this aproach is the best, it wont break future compatibility if you want to add clone to another method.
Let the user specify: ['onSet', 'onGet']
And you can leave the default behaviour where true means onGet for retro-compatiblity.

I dont know how one would neatly implement this in typescript tho.

Copy link
Owner

@arthurfiorette arthurfiorette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some linting

src/storage/memory.ts Outdated Show resolved Hide resolved
test/storage/memory.test.ts Show resolved Hide resolved
test/storage/memory.test.ts Show resolved Hide resolved
test/storage/memory.test.ts Show resolved Hide resolved
test/storage/memory.test.ts Show resolved Hide resolved
@arthurfiorette arthurfiorette linked an issue Jul 1, 2023 that may be closed by this pull request
@arthurfiorette arthurfiorette merged commit 6407cad into arthurfiorette:main Jul 1, 2023
6 checks passed
@arthurfiorette
Copy link
Owner

Thanks!

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.

Cached value serve mutated data.
2 participants