-
-
Notifications
You must be signed in to change notification settings - Fork 673
unreads: Prepare for converting to efficient data structures #4400
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
faabe2e
unread [nfc]: Start a model file; move combined reducer there.
gnprice 95742ad
unread tests: Convert stream-unreads reducer tests to whole-model style.
gnprice 335da49
unread tests: Add a missing case that the conversion highlighted.
gnprice 804c247
unread tests: Fix some impossible data.
gnprice fbb8316
unread tests: Convert selector tests to black-box style.
gnprice 7852ac6
unread tests [nfc]: Fix a wrongly-specific test description.
gnprice 6f88818
topics tests: Convert unreads data to black-box form.
gnprice 67001af
unread [nfc]: Move state type definitions into model.
gnprice 444d0e5
unread [nfc]: Move the "direct" selectors into model file.
gnprice 47496ee
topics [nfc]: Cut a few redundant type annotations.
gnprice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* @flow strict-local */ | ||
|
|
||
| import type { Message } from '../../types'; | ||
| import { reducer } from '../unreadModel'; | ||
| import * as eg from '../../__tests__/lib/exampleData'; | ||
|
|
||
| export const initialState = reducer(undefined, ({ type: eg.randString() }: $FlowFixMe)); | ||
|
|
||
| export const mkMessageAction = (message: Message) => ({ | ||
| ...eg.eventNewMessageActionBase, | ||
| message: { ...message, flags: message.flags ?? [] }, | ||
| }); | ||
|
|
||
| export const stream0 = { ...eg.makeStream({ name: 'stream 0' }), stream_id: 0 }; | ||
| export const stream2 = { ...eg.makeStream({ name: 'stream 2' }), stream_id: 2 }; | ||
|
|
||
| const [user0, user1, user2, user3, user4, user5] = [0, 1, 2, 3, 4, 5].map(user_id => | ||
| eg.makeUser({ user_id }), | ||
| ); | ||
|
|
||
| export const selectorBaseState = (() => { | ||
| let state = initialState; | ||
| for (const message of [ | ||
| eg.streamMessage({ stream_id: 0, subject: 'a topic', id: 1, flags: ['mentioned'] }), | ||
| eg.streamMessage({ stream_id: 0, subject: 'a topic', id: 2, flags: ['mentioned'] }), | ||
| eg.streamMessage({ stream_id: 0, subject: 'a topic', id: 3, flags: ['mentioned'] }), | ||
| eg.streamMessage({ stream_id: 0, subject: 'another topic', id: 4 }), | ||
| eg.streamMessage({ stream_id: 0, subject: 'another topic', id: 5 }), | ||
| eg.streamMessage({ stream_id: 2, subject: 'some other topic', id: 6 }), | ||
| eg.streamMessage({ stream_id: 2, subject: 'some other topic', id: 7 }), | ||
| // We take user1 to be self. | ||
| eg.pmMessageFromTo(user0, [user1], { id: 11 }), | ||
| eg.pmMessageFromTo(user0, [user1], { id: 12 }), | ||
| eg.pmMessageFromTo(user2, [user1], { id: 13 }), | ||
| eg.pmMessageFromTo(user2, [user1], { id: 14 }), | ||
| eg.pmMessageFromTo(user2, [user1], { id: 15 }), | ||
| eg.pmMessageFromTo(user2, [user1, user3], { id: 21 }), | ||
| eg.pmMessageFromTo(user2, [user1, user3], { id: 22 }), | ||
| eg.pmMessageFromTo(user4, [user1, user5], { id: 23 }), | ||
| eg.pmMessageFromTo(user4, [user1, user5], { id: 24 }), | ||
| eg.pmMessageFromTo(user4, [user1, user5], { id: 25 }), | ||
| ]) { | ||
| state = reducer(state, mkMessageAction(message)); | ||
| } | ||
| return state; | ||
| })(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would the
initialStateexport from unread-testlib.js do just as well aseg.baseReduxState.unread, or should we stick with the latter?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.
Ah, yes. I think it was as I was fixing up this test file (after writing most of the other changes) that I realized that
eg.baseReduxState.unreadshould be exactly equivalent to thatinitialStateexport -- after all, the point of the way we construct thatinitialState, with{ type: eg.randString() }, is that it exercises exactly the same path through the reducer that Redux uses to initialize the state. (Andeg.baseReduxStatecomes via Redux'screateStore.)I'm not entirely sure what the most helpful style is for referring to that state.
eg.baseReduxState.unreadfeels natural because it fits in with the rest of this global state we're assembling.unreadSelectors-test.js),initialStateorinitialUnreadStatefeels natural because it makes it clear that it's local -- these are the tests of this very code, so they shouldn't need to appeal to some central library to get an instance of this state.I'm inclined to leave the style different between these places at least for now, and perhaps in the future we'll settle on one of them.
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.
Sounds good; I don't have strong feelings either way.