Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

cacheSize option for defaultMemoize#210

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@b6pzeusbc54tvhw5jgpyw8pwz2x6gs

As 3rd argument, now defaultMemoize() can get thecacheSize.

There are two arrays to store previous argument arrays, previous results.

let cacheArgsArr = []let cacheREsultArr = []

cacheSize feature is designed as follows:

const createSelector = createSelectorCreator( defaultMemoize, void 0, 2 )const powerSelector = createSelector([      (state)=>state.num], ( num )=> num*num )console.log( powerSelector({ num: 1 }) )            // 1 (recomputation)console.log( powerSelector.getCacheArgsArr() )      // [ [1] ]console.log( powerSelector.getCacheResultArr() )    // [1]console.log( powerSelector({ num: 2 }) )            // 4 (recomputation)console.log( powerSelector.getCacheArgsArr() )      // [ [2],[1] ]console.log( powerSelector.getCacheResultArr() )    // [ 4, 1 ]console.log( powerSelector({ num: 3 }) )            // 9 (recomputation)console.log( powerSelector.getCacheArgsArr() )      // [ [3],[2] ]console.log( powerSelector.getCacheResultArr() )    // [ 9, 4 ]console.log( powerSelector({ num: 2 }) )            // 4 (cache)console.log( powerSelector.getCacheArgsArr() )      // [ [2],[3] ]console.log( powerSelector.getCacheResultArr() )    // [ 4, 9 ]

In general, there is high a probability that last argument is used again.
So last arguemnts and result are added or updated to index: 0 in cacheArgsArrandcacheResultArr`

Please feel free to contact us if you have something lacking.

ivawzh, Aequitas737, jballant, and alewin reacted with thumbs up emojiivawzh and adnelson reacted with heart emoji
@codecov-io
Copy link

codecov-io commentedJan 10, 2017
edited
Loading

Current coverage is 100% (diff: 100%)

Merging#210 intomaster will not change coverage

@@           master   #210   diff @@====================================  Files           1      1            Lines          12     18     +6     Methods         0      0            Messages        0      0            Branches        0      0          ====================================+ Hits           12     18     +6  Misses          0      0            Partials        0      0

Powered byCodecov. Last update1143dcb...484b0a1

@coveralls
Copy link

coveralls commentedJan 10, 2017
edited
Loading

Coverage Status

Coverage remained the same at 100.0% when pulling484b0a1 on b6pzeusbc54tvhw5jgpyw8pwz2x6gs:master into1143dcb on reactjs:master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling484b0a1 on b6pzeusbc54tvhw5jgpyw8pwz2x6gs:master into1143dcb on reactjs:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling484b0a1 on b6pzeusbc54tvhw5jgpyw8pwz2x6gs:master into1143dcb on reactjs:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling484b0a1 on b6pzeusbc54tvhw5jgpyw8pwz2x6gs:master into1143dcb on reactjs:master.

@ivawzh
Copy link

ivawzh commentedApr 21, 2018
edited
Loading

Thank@b6pzeusbc54tvhw5jgpyw8pwz2x6gs , this was an enlightenment.
What do you think about the already supported selector customization below:

importmemoizerfrom'fast-memoize'import{createSelectorCreator}from'reselect'// Why not Lodash's memoize?// Because that won't work when the function takes more than one argument. And this is fast.exportconstcreateSelector=createSelectorCreator(memoizer)

fast-memoize allows unlimited cache size.

adnelson reacted with hooray emoji

@adnelson
Copy link

@ivawzh that's a great solution -- it would be super helpful if this were in theREADME.md. It suggests to "Create a custom selector with a cache size greater than one." But doesn't provide any guidance on how to do so.

b6pzeusbc54tvhw5jgpyw8pwz2x6gs reacted with laugh emoji

@markerikson
Copy link
Contributor

Superseded by#513 .

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@b6pzeusbc54tvhw5jgpyw8pwz2x6gs@codecov-io@coveralls@ivawzh@adnelson@markerikson

[8]ページ先頭

©2009-2025 Movatter.jp