-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING: - minimum version of mobx 6 is now required - minimum version of mobx-react-lite 3 is now required
- Loading branch information
Showing
24 changed files
with
2,407 additions
and
4,424 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
# Compiled output | ||
/dist | ||
/types | ||
|
||
# Dependencies | ||
/node_modules | ||
|
This file contains 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 was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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,60 +1,60 @@ | ||
// eslint-disable-next-line | ||
import React from 'react'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { Route, RouteParams, QueryParams } from '../route'; | ||
import { Store, RouterStore } from '../router-store'; | ||
|
||
const LinkBase = < | ||
S extends Store, | ||
P extends RouteParams, | ||
Q extends QueryParams | ||
>({ | ||
route, | ||
className, | ||
params, | ||
queryParams, | ||
refresh = false, | ||
style = {}, | ||
children, | ||
title, | ||
router | ||
}: React.PropsWithChildren<{ | ||
route: Route<S, P, Q>; | ||
className?: string; | ||
params?: P; | ||
queryParams?: Q; | ||
refresh?: boolean; | ||
style?: React.StyleHTMLAttributes<HTMLAnchorElement>; | ||
title?: string; | ||
router: RouterStore<S>; | ||
}>) => { | ||
if (!router) { | ||
console.error( | ||
'The router prop must be defined for a Link component to work!' | ||
); | ||
return null; | ||
} | ||
return ( | ||
<a | ||
style={style} | ||
className={className} | ||
onClick={e => { | ||
const middleClick = e.button === 2; | ||
const cmdOrCtrl = e.metaKey || e.ctrlKey; | ||
const openinNewTab = middleClick || cmdOrCtrl; | ||
const shouldNavigateManually = | ||
refresh || openinNewTab || cmdOrCtrl; | ||
|
||
if (!shouldNavigateManually) { | ||
e.preventDefault(); | ||
router.goTo(route, params, queryParams); | ||
} | ||
}} | ||
href={route.replaceUrlParams(params, queryParams)} | ||
> | ||
{title || children} | ||
</a> | ||
); | ||
}; | ||
|
||
export const Link = observer(LinkBase); | ||
// eslint-disable-next-line | ||
import React from 'react'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { Route, RouteParams, QueryParams } from '../route'; | ||
import { Store, RouterStore } from '../router-store'; | ||
|
||
const LinkBase = < | ||
S extends Store, | ||
P extends RouteParams, | ||
Q extends QueryParams | ||
>({ | ||
route, | ||
className, | ||
params, | ||
queryParams, | ||
refresh = false, | ||
style = {}, | ||
children, | ||
title, | ||
router, | ||
}: React.PropsWithChildren<{ | ||
route: Route<S, P, Q>; | ||
className?: string; | ||
params?: P; | ||
queryParams?: Q; | ||
refresh?: boolean; | ||
style?: React.StyleHTMLAttributes<HTMLAnchorElement>; | ||
title?: string; | ||
router: RouterStore<S>; | ||
}>) => { | ||
if (!router) { | ||
console.error( | ||
'The router prop must be defined for a Link component to work!' | ||
); | ||
return null; | ||
} | ||
return ( | ||
<a | ||
style={style} | ||
className={className} | ||
onClick={(e) => { | ||
const middleClick = e.button === 2; | ||
const cmdOrCtrl = e.metaKey || e.ctrlKey; | ||
const openinNewTab = middleClick || cmdOrCtrl; | ||
const shouldNavigateManually = | ||
refresh || openinNewTab || cmdOrCtrl; | ||
|
||
if (!shouldNavigateManually) { | ||
e.preventDefault(); | ||
router.goTo(route, params, queryParams); | ||
} | ||
}} | ||
href={route.replaceUrlParams(params, queryParams)} | ||
> | ||
{title || children} | ||
</a> | ||
); | ||
}; | ||
|
||
export const Link = observer(LinkBase); |
This file contains 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,18 +1,18 @@ | ||
// eslint-disable-next-line | ||
import React from 'react'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { Store } from '../router-store'; | ||
|
||
type Props = { store: Store }; | ||
|
||
export const MobxRouter = observer(({ store: { router } }: Props) => { | ||
return ( | ||
<> | ||
{router.currentRoute && router.currentRoute.component ? ( | ||
router.currentRoute.component | ||
) : ( | ||
<div /> | ||
)} | ||
</> | ||
); | ||
}); | ||
// eslint-disable-next-line | ||
import React from 'react'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { Store } from '../router-store'; | ||
|
||
type Props = { store: Store }; | ||
|
||
export const MobxRouter = observer(({ store: { router } }: Props) => { | ||
return ( | ||
<> | ||
{router.currentRoute && router.currentRoute.component ? ( | ||
router.currentRoute.component | ||
) : ( | ||
<div /> | ||
)} | ||
</> | ||
); | ||
}); |
This file contains 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 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.