Skip to content
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

refactor(router-plugin): mark selectors as pure #2248

Merged
merged 1 commit into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $ npm install @ngxs/store@dev
- Fix(store): Prevent writing to state once action handler is unsubscribed [#2231](https://github.com/ngxs/store/pull/2231)
- Performance(store): Replace `instanceof Function` with `typeof` [#2247](https://github.com/ngxs/store/pull/2247)
- Refactor(store): Use `Object.is` as default equality check [#2245](https://github.com/ngxs/store/pull/2245)
- Refactor(router-plugin): Mark selectors as pure [#2248](https://github.com/ngxs/store/pull/2248)

### 18.1.4 2024-10-23

Expand Down
24 changes: 13 additions & 11 deletions packages/router-plugin/src/router.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
NavigationEnd,
Event
} from '@angular/router';
import { Action, Selector, State, StateContext, StateToken, Store } from '@ngxs/store';
import { Action, createSelector, State, StateContext, StateToken, Store } from '@ngxs/store';
import {
NavigationActionTiming,
NgxsRouterPluginOptions,
Expand Down Expand Up @@ -81,17 +81,19 @@ export class RouterState implements OnDestroy {

private _destroy$ = new ReplaySubject<void>(1);

@Selector()
static state<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;
}
static state = /* @__PURE__ */ createSelector(
[ROUTER_STATE_TOKEN],
(state: RouterStateModel<RouterStateSnapshot>) => {
// The `state` is optional if the selector is invoked before the router
// state is registered in NGXS.
return state?.state;
}
);

@Selector()
static url(state: RouterStateModel): string | undefined {
return state?.state?.url;
}
static url = /* @__PURE__ */ createSelector(
[ROUTER_STATE_TOKEN],
state => state?.state?.url
);

constructor(
private _store: Store,
Expand Down
Loading