-
Notifications
You must be signed in to change notification settings - Fork 45
feat(devtools): display event payloads for withTrackedReducer #295
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
Open
OleksandrOleniuk
wants to merge
2
commits into
angular-architects:main
Choose a base branch
from
OleksandrOleniuk:with-tracked-reducer-events
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,63 @@ | ||
| import { Action } from '@ngrx/store'; | ||
| import { expect, test } from '@playwright/test'; | ||
|
|
||
| test.describe('events-sample + devtools', () => { | ||
| test('DevTools are syncing events and payloads', async ({ page }) => { | ||
| await page.goto(''); | ||
|
|
||
| await page.evaluate(() => { | ||
| window['devtoolsSpy'] = []; | ||
|
|
||
| window['__REDUX_DEVTOOLS_EXTENSION__'] = { | ||
| connect: () => { | ||
| return { | ||
| send: (data: Action) => { | ||
| window['devtoolsSpy'].push(data); | ||
| }, | ||
| }; | ||
| }, | ||
| }; | ||
| }); | ||
|
|
||
| await page.getByRole('link', { name: 'Events + DevTools Sample' }).click(); | ||
|
|
||
| // Filter by title | ||
| await page.getByPlaceholder('Filter by title or author...').fill('Hobbit'); | ||
|
|
||
| // Add Book (Random) | ||
| await page.getByRole('button', { name: 'Add Book' }).click(); | ||
|
|
||
| // Clear Selection | ||
| await page.getByRole('button', { name: 'Clear Selection' }).click(); | ||
|
|
||
| const devtoolsActions = await page.evaluate(() => window['devtoolsSpy']); | ||
|
|
||
| // Check if filterUpdated event was tracked with the expected payload | ||
| const filterEvent = devtoolsActions.find( | ||
| (a) => a.type === '[Book Store] filterUpdated', | ||
| ); | ||
| expect(filterEvent).toBeDefined(); | ||
| expect(filterEvent).toEqual({ | ||
| type: '[Book Store] filterUpdated', | ||
| payload: { filter: 'Hobbit' }, | ||
| }); | ||
|
|
||
| // Check selectionCleared event | ||
| const clearSelectionEvent = devtoolsActions.find( | ||
| (a) => a.type === '[Book Store] selectionCleared', | ||
| ); | ||
| expect(clearSelectionEvent).toBeDefined(); | ||
| expect(clearSelectionEvent).toEqual({ | ||
| type: '[Book Store] selectionCleared', | ||
| }); | ||
|
|
||
| // Check bookAdded event (payload will contain random book, so just check if payload has book object) | ||
| const bookAddedEvent = devtoolsActions.find( | ||
| (a) => a.type === '[Book Store] bookAdded', | ||
| ); | ||
| expect(bookAddedEvent).toBeDefined(); | ||
| expect(bookAddedEvent.payload).toBeDefined(); | ||
| expect(bookAddedEvent.payload.book).toBeDefined(); | ||
| expect(bookAddedEvent.payload.book).toHaveProperty('title'); | ||
| }); | ||
| }); |
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
4 changes: 4 additions & 0 deletions
4
libs/ngrx-toolkit/src/lib/devtools/internal/current-action-names.ts
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 |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| import { EventInstance } from '@ngrx/signals/events'; | ||
|
|
||
| export const currentActionNames = new Set<string>(); | ||
|
|
||
| export const currentEvents = new Set<EventInstance<string, any>>(); | ||
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
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.
to be honest, I think we don't even have to bring a queue for the events.
withTrackedReducershould consume the event and immediately send it devtools.The action names were only necessary when are collecting the state changes via an
effect.Because of that, I think this whole PR could be much shorter.
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.
Thanks for the comment
I just based it on the existing functionality. Could you explain what do you mean by
I could inject
DevtoolsSyncerafterupdateStateand call some syncing, but i don't think this is a nice way