Skip to content

Conversation

@arturovt
Copy link
Member

@arturovt arturovt commented Jan 12, 2025

In this commit, we switch from using the selector decorator to allow it to be dropped in production
for apps that don't use it at all.

Breaking change: To get the RouterState.state, it is now required to call the state
function — select(RouterState.state()). Previously, it was possible to provide a generic type for
the router state, e.g., select(RouterState.state<CustomRouterState>), but this is not possible
if state were a property.

@nx-cloud
Copy link

nx-cloud bot commented Jan 12, 2025

View your CI Pipeline Execution ↗ for commit 9f62f20.

Command Status Duration Result
nx run-many --target=lint --all --exclude=creat... ✅ Succeeded 1s View ↗
nx run-many --target=test --all --configuration... ✅ Succeeded 2s View ↗
nx lint-types store ✅ Succeeded <1s View ↗
nx run-many --target=build --all ✅ Succeeded 2s View ↗

☁️ Nx Cloud last updated this comment at 2025-01-13 11:22:50 UTC

@arturovt arturovt force-pushed the refactor/router-state-selector-decorator branch 2 times, most recently from 03977cb to e63f170 Compare January 12, 2025 19:00
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 12, 2025

Open in Stackblitz

@ngxs/devtools-plugin

npm i https://pkg.pr.new/@ngxs/devtools-plugin@2294

@ngxs/hmr-plugin

npm i https://pkg.pr.new/@ngxs/hmr-plugin@2294

@ngxs/form-plugin

npm i https://pkg.pr.new/@ngxs/form-plugin@2294

@ngxs/storage-plugin

npm i https://pkg.pr.new/@ngxs/storage-plugin@2294

@ngxs/router-plugin

npm i https://pkg.pr.new/@ngxs/router-plugin@2294

@ngxs/store

npm i https://pkg.pr.new/@ngxs/store@2294

@ngxs/websocket-plugin

npm i https://pkg.pr.new/@ngxs/websocket-plugin@2294

commit: 9f62f20

@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit e63f170 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (50% is the threshold).

This pull request will bring the total coverage in the repository to 95.3% (0.0% change).

View more on Code Climate.

@bundlemon
Copy link

bundlemon bot commented Jan 12, 2025

BundleMon

Unchanged files (6)
Status Path Size Limits
fesm2022/ngxs-store.mjs
104.93KB 105KB / +0.5%
fesm2022/ngxs-store-internals.mjs
11.82KB 13KB / +0.5%
fesm2022/ngxs-store-internals-testing.mjs
6.8KB 7KB / +0.5%
fesm2022/ngxs-store-operators.mjs
6.22KB 7KB / +0.5%
fesm2022/ngxs-store-plugins.mjs
2.38KB 3KB / +0.5%
fesm2022/ngxs-store-experimental.mjs
574B 2KB / +0.5%

No change in files bundle size

Unchanged groups (1)
Status Path Size Limits
@ngxs/store(fesm2022)[gzip]
./fesm2022/*.mjs
31.94KB +1%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@bundlemon
Copy link

bundlemon bot commented Jan 12, 2025

BundleMon (NGXS Plugins)

Unchanged files (9)
Status Path Size Limits
Plugins(fesm2022)[gzip]
storage-plugin/fesm2022/ngxs-storage-plugin.m
js
3.98KB +0.5%
Plugins(fesm2022)[gzip]
router-plugin/fesm2022/ngxs-router-plugin.mjs
2.96KB +0.5%
Plugins(fesm2022)[gzip]
hmr-plugin/fesm2022/ngxs-hmr-plugin.mjs
2.63KB +0.5%
Plugins(fesm2022)[gzip]
websocket-plugin/fesm2022/ngxs-websocket-plug
in.mjs
2.56KB +0.5%
Plugins(fesm2022)[gzip]
form-plugin/fesm2022/ngxs-form-plugin.mjs
2.46KB +0.5%
Plugins(fesm2022)[gzip]
devtools-plugin/fesm2022/ngxs-devtools-plugin
.mjs
2.15KB +0.5%
Plugins(fesm2022)[gzip]
logger-plugin/fesm2022/ngxs-logger-plugin.mjs
2.01KB +0.5%
Plugins(fesm2022)[gzip]
storage-plugin/fesm2022/ngxs-storage-plugin-i
nternals.mjs
861B +0.5%
Plugins(fesm2022)[gzip]
router-plugin/fesm2022/ngxs-router-plugin-int
ernals.mjs
396B +0.5%

Total files change -2B -0.01%

Unchanged groups (1)
Status Path Size Limits
All Plugins(fesm2022)[gzip]
./-plugin/fesm2022/.mjs
19.96KB +0.5%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@bundlemon
Copy link

bundlemon bot commented Jan 12, 2025

BundleMon (Integration Projects)

Files added (1)
Status Path Size Limits
Main bundles(Gzip)
hello-world-ng19/dist-integration/browser/mai
n-(hash).js
+66.28KB +1%
Files removed (3)
Status Path Size Limits
Main bundles(Gzip)
hello-world-ng18/dist-integration/browser/mai
n-(hash).js
-70.1KB +1%
Main bundles(Gzip)
hello-world-ng17/dist-integration/main.(hash)
.js
-68.24KB +1%
Main bundles(Gzip)
hello-world-ng16/dist-integration/main.(hash)
.js
-67.3KB +1%

Total files change -139.36KB -67.77%

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

In this commit, we switch from using the selector decorator to allow it to be dropped in production
for apps that don't use it at all.

Breaking change: To get the `RouterState.state`, it is now required to call the `state`
function — `select(RouterState.state())`. Previously, it was possible to provide a generic type for
the router state, e.g., `select(RouterState.state<CustomRouterState>)`, but this is not possible
if `state` were a property.
@arturovt arturovt force-pushed the refactor/router-state-selector-decorator branch from e63f170 to 9f62f20 Compare January 13, 2025 11:19
@arturovt arturovt marked this pull request as ready for review January 13, 2025 11:20
@arturovt arturovt merged commit 934d9e1 into master Jan 13, 2025
5 checks passed
@arturovt arturovt deleted the refactor/router-state-selector-decorator branch January 13, 2025 11:21
Comment on lines +88 to +93
static state<T = RouterStateSnapshot>() {
return createSelector([ROUTER_STATE_TOKEN], (state: RouterStateModel<T>) => {
// The `state` is optional if the selector is invoked before the router
// state is registered in NGXS.
return state?.state;
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arturovt Isn't this a breaking change because it is updating the public API?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see that now that this is mentioned in the PR description. I think that there needs to be a note in the changelog about this breaking change.
Or do you think that there is an alternative like a separate getRouterState<T>() dynamic selector exposed by the plugin, and we leave the RouterState.state as a property.
OR is there the possibility of:
RouterState<RouterStateSnapshot>.state where the T on RouterState has a default so that RouterState.state still works.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm.... I think I have figured out how to make this a non breaking change:

Suggested change
static state<T = RouterStateSnapshot>() {
return createSelector([ROUTER_STATE_TOKEN], (state: RouterStateModel<T>) => {
// The `state` is optional if the selector is invoked before the router
// state is registered in NGXS.
return state?.state;
});
static get state() {
return createSelector([ROUTER_STATE_TOKEN], <T = RouterStateSnapshot>(state: RouterStateModel<T>) => {
// The `state` is optional if the selector is invoked before the router
// state is registered in NGXS.
return state?.state;
});

I made a StackBlitz example here:
https://stackblitz.com/edit/vitejs-vite-rrj1efj4?file=src%2Fcounter.ts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't work, unfortunately:

image

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants