Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

feat: accept router to be a function #22

Merged
merged 5 commits into from
Jul 23, 2019

Conversation

osdnk
Copy link
Member

@osdnk osdnk commented Jul 21, 2019

No description provided.

@codecov-io
Copy link

codecov-io commented Jul 21, 2019

Codecov Report

Merging #22 into master will increase coverage by 2.69%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #22      +/-   ##
==========================================
+ Coverage   89.51%   92.21%   +2.69%     
==========================================
  Files          18       16       -2     
  Lines         248      244       -4     
  Branches       58       58              
==========================================
+ Hits          222      225       +3     
+ Misses         24       17       -7     
  Partials        2        2
Impacted Files Coverage Δ
src/useNavigationBuilder.tsx 100% <100%> (ø) ⬆️
src/__tests__/__fixtures__/MockRouter.tsx 95.45% <100%> (+4.97%) ⬆️
src/createNavigator.tsx
src/useNavigation.tsx

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 58f5b0e...fec3e7f. Read the comment docs.

@osdnk osdnk changed the base branch from master to @satya164/set-options July 21, 2019 20:58
@satya164
Copy link
Member

Can you drop the commit regarding setOptions and rebase against master so it's easier to review?

@satya164 satya164 force-pushed the @satya164/set-options branch 2 times, most recently from 109e1f1 to 0519693 Compare July 22, 2019 15:03
@osdnk
Copy link
Member Author

osdnk commented Jul 22, 2019

@satya164 My changes are built on thew top of yours. If you're force-pushed commit with another hash, it might imply problems. I can do it after merging your PR.

@satya164 satya164 force-pushed the @satya164/set-options branch 2 times, most recently from 6793b09 to 83477e3 Compare July 22, 2019 16:34
@satya164 satya164 force-pushed the @osdnk/allow-router-to-be-a-function branch from e980e36 to 56fb0fa Compare July 22, 2019 19:09
@satya164 satya164 changed the base branch from @satya164/set-options to master July 22, 2019 19:09
Options extends DefualtOptions = DefualtOptions
>(router: RouterHelper<any, Options>, options: Options) {
const { current: currentRouter } = React.useRef<Router<any>>(
typeof router === 'function' ? router(options) : router
Copy link
Member

Choose a reason for hiding this comment

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

I think it's better to just always make it a function rather than accepting both object and function

Copy link
Member

Choose a reason for hiding this comment

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

I think we shouldn't pass things like children to the router. It'll be problematic if someone writing a custom router uses children.

@@ -79,7 +84,7 @@ export default function useNavigationBuilder<ScreenOptions extends object>(
);

const [initialState] = React.useState(() =>
router.getInitialState({
currentRouter.getInitialState({
routeNames,
initialRouteName,
Copy link
Member

Choose a reason for hiding this comment

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

Since we now pass initialRouteName as an option, we could remove it from here

@@ -79,7 +84,7 @@ export default function useNavigationBuilder<ScreenOptions extends object>(
);

const [initialState] = React.useState(() =>
router.getInitialState({
currentRouter.getInitialState({
routeNames,
initialRouteName,
initialParamsList,
Copy link
Member

Choose a reason for hiding this comment

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

Let's rename this to routeParamList, since it's not really initial as it changes when children change.

ScreenOptions extends object,
Options extends DefualtOptions = DefualtOptions
>(router: RouterHelper<any, Options>, options: Options) {
const { current: currentRouter } = React.useRef<Router<any>>(
Copy link
Member

Choose a reason for hiding this comment

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

Since there's always going to be one router, I think no need to say currentRouter, router looks nicer 😛

) {
export default function useNavigationBuilder<
ScreenOptions extends object,
Options extends DefualtOptions = DefualtOptions
Copy link
Member

Choose a reason for hiding this comment

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

RouterOptions

src/types.tsx Outdated
@@ -55,6 +56,16 @@ export type ActionCreators<Action extends NavigationAction> = {
[key: string]: (...args: any) => Action;
};

export type DefualtOptions = {
Copy link
Member

Choose a reason for hiding this comment

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

RouterDefaultOptions

@osdnk osdnk force-pushed the @osdnk/allow-router-to-be-a-function branch from e3d24a8 to e81116a Compare July 23, 2019 20:48
src/types.tsx Show resolved Hide resolved
src/types.tsx Show resolved Hide resolved
src/types.tsx Outdated Show resolved Hide resolved
src/types.tsx Outdated Show resolved Hide resolved
@satya164 satya164 force-pushed the @osdnk/allow-router-to-be-a-function branch from 69eceed to fec3e7f Compare July 23, 2019 21:16
@satya164 satya164 merged commit 9a86fda into master Jul 23, 2019
@satya164 satya164 deleted the @osdnk/allow-router-to-be-a-function branch July 23, 2019 21:21
satya164 pushed a commit that referenced this pull request Aug 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants