Skip to content

Commit

Permalink
feat: new function filterForOnlyQueryParamsChanged (#133)
Browse files Browse the repository at this point in the history
* fix: correct functionname to provideAppStateServiceMock

* feat: new function filterForOnlyQueryParamsChanged

---------

Co-authored-by: kim.tran <[email protected]>
  • Loading branch information
KimFFVII and kim.tran authored Feb 19, 2024
1 parent 0c0b191 commit caa2993
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Router, RoutesRecognized } from '@angular/router'
import { RouterNavigatedAction } from '@ngrx/router-store'
import { filter, map, MonoTypeOperatorFunction, withLatestFrom } from 'rxjs'

export function filterForOnlyQueryParamsChanged<A extends RouterNavigatedAction>(
router: Router
): MonoTypeOperatorFunction<A> {
return (source) => {
return source.pipe(
withLatestFrom(
router.events.pipe(
filter((e) => e instanceof RoutesRecognized),
map(() => router.routerState)
)
),
filter(([action, previousRouterState]) => {
const previousPath = previousRouterState.snapshot.url.split('?')[0]
const currentPath = action.payload.event.urlAfterRedirects.split('?')[0]

return previousPath !== currentPath
}),
map(([action]) => action)
)
}
}
1 change: 1 addition & 0 deletions libs/portal-integration-angular/ngrx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './create-child-selectors'
export * from './create-query-params-effect'
export * from './filter-for-navigated-to'
export * from './filter-for-query-params-changed'
export * from './filter-for-only-query-params-changed'

0 comments on commit caa2993

Please sign in to comment.