Repository navigation
Try: use 'frecency' to sort items in the inserters - #5342
Conversation
Use a heuristic that combines frequency and recency to sort the items that appear in the two inserters. The scoring function used is borrowed from z, an open source command line tool: https://github.com/rupa/z
youknowriad
left a comment
There was a problem hiding this comment.
Code wise, this is looking good. I'll defer to @jasmussen and @karmatosed for the algorithm.
|
This seems good to me, though it's hard to test quickly as almost by definition we have to let this run for a while to test it. 👍 👍 |
|
Should we change the label? |
Yes good point, it's not recent anymore. Stumbling as to what though. Maybe we just don't have a label and say blocks, then library? |
|
It's too long, but for reference Slack uses "Frequently Used". |
|
What about just "Frequent" to make it shorter? |
|
Frequent 👍 (Or "Frecent"? 😉) |
|
"Popular" |
|
I've renamed the tab to Frequent 🙂 |
| insertUsage: { | ||
| ...prevState.insertUsage, | ||
| [ id ]: { | ||
| time: Date.now(), |
There was a problem hiding this comment.
Pedantry: Date.now makes this reducer impure:
https://en.wikipedia.org/wiki/Functional_programming#Pure_functions
If a pure function is called with arguments that cause no side-effects, the result is constant with respect to that argument list ... i.e., if calling the pure function again with the same arguments returns the same result.
Violating a core principle of Redux:
Reducers are just pure functions that take the previous state and an action, and return the next state.
https://redux.js.org/introduction/three-principles#changes-are-made-with-pure-functions
There was a problem hiding this comment.
You're totally right. I'll move this to the action creator.
| ], | ||
| insertUsage: { | ||
| 'core-embed/twitter': { | ||
| time: expect.any( Number ), |
There was a problem hiding this comment.
To the above point, we shouldn't have any need for expect.any in this file, given that a reducer should be deterministic.
|
Out of curiosity, since Wondering about some of the selector arithmetic around |
|
Good point. |
Closes #5320.
Quick attempt at using frecency—a heuristic that combines frequency and recency—to sort the items that appear in both the main inserter and the quick inserter.
The scoring function I used is borrowed from z, an open source command line tool. We'll likely want to adjust the algorithm based on what feels right.
To test, insert a few different blocks and look at how that affects the Recent tab in the inserter. Recently inserted blocks should move to the top of the list, but they shouldn't displace very frequently used blocks.