-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add SubscriptionViewModel base class #30297
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
71 commits
Select commit
Hold shift + click to select a range
15817cf
Very first pass at shared component views
dbkr ddbe098
Remove old TextualEvent
dbkr 0179284
Pass showHiddenEvents
dbkr 84d34e1
Factor out common view model stuff
dbkr b96da8d
Move ViewModel interface into the shared components
dbkr 455ca44
Add tiny wrapper hook
dbkr 73d78f4
Move showHiddenEvents into props fully
dbkr 2125415
Fill in stories / test
dbkr a597221
chore: setup storybook
florianduros 3d724ff
Add TextualEvent component to storybook
dbkr 11f9849
Add mock view model & snapshot
dbkr 4709656
Remove old style stories entry
dbkr 5638dd7
Merge branch 'develop' into dbkr/textualevent_sharedcomponent
dbkr 9318006
Change import
dbkr a936433
Change import
dbkr 472de3b
Prettier
dbkr 073d97e
Add paxckage patch to @types/mdx
dbkr f2fc88f
Merge remote-tracking branch 'origin/develop' into dbkr/textualevent_…
dbkr 862aaff
Pass getSnapshot as getServerSnapshot too
dbkr 82d08df
Maybe make sonar regognise tests as tests
dbkr b1edabe
Typo
dbkr 3285007
Use storybook reacvt-vite
dbkr 4fddd23
Change here too
dbkr 703ba8d
Workaround for incomatible types in rollup
dbkr fbe6a06
Remove webpack styling addon
dbkr c8bd639
Merge remote-tracking branch 'origin/develop' into dbkr/textualevent_…
dbkr 7e4ff89
Hopefully do screenshot testing...
dbkr d3300ac
need newer node
dbkr 5f3fae2
quote issues
dbkr d3c5971
Make it an npm script
dbkr f47673c
colons
dbkr 0c3830f
use right port
dbkr 41612d3
Install playwright browsers
dbkr fd9253d
Try without the if
dbkr 2f62c15
Oh right, we need the headless shell
dbkr d2c632f
Pass flag to store received screenshots
dbkr b632a61
Update snapshot from received
dbkr 80ed90a
Include platform in snapshot / received dir
dbkr a56cf55
Suffix snapshots with platform instead
dbkr 917f85e
Remove unnecessary env vars
dbkr 6171d2a
Add some comments
dbkr 94b7adc
Prettier
dbkr 5a2cb98
Merge remote-tracking branch 'origin/develop' into dbkr/textualevent_…
dbkr f424599
Fix yarn.lock
dbkr e6dbe93
Memoise vm creation
dbkr 7347d55
Add implements
dbkr b4ea530
Fix listener interface
dbkr 3077be3
Add implements
dbkr 9621f79
Merge remote-tracking branch 'origin/develop' into dbkr/textualevent_…
dbkr 03ee035
Fix types
dbkr fbd9af6
Fix more types
dbkr 056b06e
Add a superclass that simple view models can extend
dbkr 8878c7b
Revert useMemo
dbkr 626022e
Merge branch 'dbkr/textualevent_sharedcomponent' into dbkr/subscripti…
dbkr 553724b
Unused import
dbkr 117bba4
Merge branch 'dbkr/textualevent_sharedcomponent' into dbkr/subscripti…
dbkr 86e7d99
Actually commit the file the branch is named after
dbkr ead893c
Merge remote-tracking branch 'origin/develop' into dbkr/textualevent_…
dbkr fa300af
Add missing playwright step
dbkr dc47abb
Add return type annotation
dbkr f62177a
Change to add / remove subscription callback
dbkr 049a3ae
Change to 'add' rather than 'subs.subscribe'
dbkr b124415
Merge branch 'dbkr/textualevent_sharedcomponent' into dbkr/subscripti…
dbkr c16fd3d
Add cache specifier for only shell playwright browsers
dbkr c3e53aa
Add copyright headers
dbkr a373a68
Merge branch 'dbkr/textualevent_sharedcomponent' into dbkr/subscripti…
dbkr 36940a4
Merge branch 'develop' into dbkr/subscriptionviewmodel
dbkr 6cd968d
Better comment wording
dbkr fc83ec4
Make amit an arrow function
dbkr 8c7529c
Add a test
dbkr 8d8f9a7
Merge branch 'develop' into dbkr/subscriptionviewmodel
dbkr 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| Copyright 2025 New Vector Ltd. | ||
|
|
||
| SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial | ||
| Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| import { type ViewModel } from "../shared-components/ViewModel"; | ||
| import { ViewModelSubscriptions } from "./ViewModelSubscriptions"; | ||
|
|
||
| export abstract class SubscriptionViewModel<T> implements ViewModel<T> { | ||
| protected subs: ViewModelSubscriptions; | ||
|
|
||
| protected constructor() { | ||
| this.subs = new ViewModelSubscriptions( | ||
| this.addDownstreamSubscriptionWrapper, | ||
| this.removeDownstreamSubscriptionWrapper, | ||
| ); | ||
| } | ||
|
|
||
| public subscribe = (listener: () => void): (() => void) => { | ||
| return this.subs.add(listener); | ||
| }; | ||
|
|
||
| /** | ||
| * Wrapper around the abstract subscribe callback as we can't assume that the subclassed method | ||
| * has a bound `this` context. | ||
| */ | ||
| private addDownstreamSubscriptionWrapper = (): void => { | ||
| this.addDownstreamSubscription(); | ||
| }; | ||
|
|
||
| /** | ||
| * Wrapper around the abstract unsubscribe callback as we can't call pass an abstract method directly | ||
| * in the constructor. | ||
| */ | ||
| private removeDownstreamSubscriptionWrapper = (): void => { | ||
| this.removeDownstreamSubscription(); | ||
| }; | ||
|
|
||
| /** | ||
| * Called when the first listener subscribes: the subclass should set up any necessary subscriptions | ||
| * to call this.subs.emit() when the snapshot changes. | ||
| */ | ||
| protected abstract addDownstreamSubscription(): void; | ||
|
|
||
| /** | ||
| * Called when the last listener unsubscribes: the subclass should clean up any subscriptions. | ||
| */ | ||
| protected abstract removeDownstreamSubscription(): void; | ||
|
|
||
| /** | ||
| * Returns the current snapshot of the view model. | ||
| */ | ||
| public abstract getSnapshot: () => T; | ||
| } |
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,29 @@ | ||
| /* | ||
| Copyright 2025 New Vector Ltd. | ||
|
|
||
| SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial | ||
| Please see LICENSE files in the repository root for full details. | ||
| */ | ||
|
|
||
| import { MatrixEvent, MatrixEventEvent } from "matrix-js-sdk/src/matrix"; | ||
|
|
||
| import { TextualEventViewModel } from "../../../src/viewmodels/event-tiles/TextualEventViewModel"; | ||
|
|
||
| describe("TextualEventViewModel", () => { | ||
| it("should update when the sentinel updates", () => { | ||
| const fakeEvent = new MatrixEvent({}); | ||
|
|
||
| const vm = new TextualEventViewModel({ | ||
| showHiddenEvents: false, | ||
| mxEvent: fakeEvent, | ||
| }); | ||
|
|
||
| const cb = jest.fn(); | ||
|
|
||
| vm.subscribe(cb); | ||
|
|
||
| fakeEvent.emit(MatrixEventEvent.SentinelUpdated); | ||
|
|
||
| expect(cb).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
emit called in this way will have no
thisreference as it is not an arrow-function or boundThere 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.
Good point: I've made
emitan arrow function and added a test to asset it actually works.