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

Export isSameRouteMatch from react-resource-router/utils #213

Merged
merged 2 commits into from
Aug 16, 2023
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
2 changes: 1 addition & 1 deletion src/common/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export {
warmupMatchRouteCache,
} from './match-route';
export { findRouterContext, createRouterContext } from './router-context';
export { isSameRoute } from './is-same-route';
export { isSameRouteMatch } from './is-same-route';
2 changes: 1 addition & 1 deletion src/common/utils/is-same-route/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const isShallowEqual = (o1: ObjectToCompare, o2: ObjectToCompare) => {
return objKeys1.every(key => o1[key] === o2[key]);
};

export const isSameRoute = ({
export const isSameRouteMatch = ({
prevContextMatch,
nextContextMatch,
}: {
Expand Down
26 changes: 19 additions & 7 deletions src/common/utils/is-same-route/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isSameRoute } from './index';
import { isSameRouteMatch } from './index';

describe('isSameRoute', () => {
it('should be true', () => {
Expand All @@ -17,7 +17,9 @@ describe('isSameRoute', () => {
url: '',
query: {},
};
expect(isSameRoute({ prevContextMatch, nextContextMatch })).toBeTruthy();
expect(
isSameRouteMatch({ prevContextMatch, nextContextMatch })
).toBeTruthy();
});

it('should be false, as "query" is different', () => {
Expand All @@ -38,7 +40,9 @@ describe('isSameRoute', () => {
a: '1',
},
};
expect(isSameRoute({ prevContextMatch, nextContextMatch })).toBeFalsy();
expect(
isSameRouteMatch({ prevContextMatch, nextContextMatch })
).toBeFalsy();
});

it('should be false, as "params" are different', () => {
Expand All @@ -59,7 +63,9 @@ describe('isSameRoute', () => {
url: '',
query: {},
};
expect(isSameRoute({ prevContextMatch, nextContextMatch })).toBeFalsy();
expect(
isSameRouteMatch({ prevContextMatch, nextContextMatch })
).toBeFalsy();
});

it('should be false, as "path" is different', () => {
Expand All @@ -78,7 +84,9 @@ describe('isSameRoute', () => {
url: '',
query: {},
};
expect(isSameRoute({ prevContextMatch, nextContextMatch })).toBeFalsy();
expect(
isSameRouteMatch({ prevContextMatch, nextContextMatch })
).toBeFalsy();
});

it('should return true, even though "query" props are in different order', () => {
Expand All @@ -103,7 +111,9 @@ describe('isSameRoute', () => {
a: '1',
},
};
expect(isSameRoute({ prevContextMatch, nextContextMatch })).toBeTruthy();
expect(
isSameRouteMatch({ prevContextMatch, nextContextMatch })
).toBeTruthy();
});

it('should return true, even though "params" props are in different order', () => {
Expand All @@ -128,6 +138,8 @@ describe('isSameRoute', () => {
url: '',
query: {},
};
expect(isSameRoute({ prevContextMatch, nextContextMatch })).toBeTruthy();
expect(
isSameRouteMatch({ prevContextMatch, nextContextMatch })
).toBeTruthy();
});
});
4 changes: 2 additions & 2 deletions src/controllers/router-store/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import URL, { qs } from 'url-parse';

import { Href, Location, Query, RouterContext } from '../../../common/types';
import { isSameRoute } from '../../../common/utils';
import { isSameRouteMatch } from '../../../common/utils';

const stripTrailingSlash = (path: string) =>
path.charAt(path.length - 1) === '/' ? path.slice(0, -1) : path;
Expand Down Expand Up @@ -75,7 +75,7 @@ export const shouldReload = ({
prevContext: RouterContext;
pluginId: string;
}) => {
const sameRoute = isSameRoute({
const sameRoute = isSameRouteMatch({
prevContextMatch: prevContext.match,
nextContextMatch: context.match,
});
Expand Down
8 changes: 4 additions & 4 deletions src/controllers/router-store/utils/test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isSameRoute } from '../../../common/utils';
import { isSameRouteMatch } from '../../../common/utils';
import { mockRouteContext } from '../../../mocks';

import {
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('sanitizePath()', () => {

describe('shouldReload()', () => {
beforeEach(() => {
(isSameRoute as any).mockReturnValue(false);
(isSameRouteMatch as any).mockReturnValue(false);
});
it('should return defaultValue when routes are not the same', () => {
const context = {
Expand Down Expand Up @@ -246,7 +246,7 @@ describe('shouldReload()', () => {
});

it("should return defaultValue=false as route haven't changed", () => {
(isSameRoute as any).mockReturnValue(true);
(isSameRouteMatch as any).mockReturnValue(true);
const context = {
...mockRouteContext,
};
Expand All @@ -264,7 +264,7 @@ describe('shouldReload()', () => {
});

it('should return defaultValue=true for resources-plugin', () => {
(isSameRoute as any).mockReturnValue(true);
(isSameRouteMatch as any).mockReturnValue(true);
const context = {
...mockRouteContext,
};
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export {
findRouterContext,
matchRoute,
matchInvariantRoute,
isSameRouteMatch,
} from './common/utils';

export { shouldReloadWhenRouteMatchChanges } from './common/utils/should-reload-when-route-match-changes';
Loading