Skip to content

Commit

Permalink
Update resource flow definition (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertogasparin authored Nov 1, 2020
1 parent 33d0927 commit 3ca7a02
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 43 deletions.
6 changes: 1 addition & 5 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@
[lints]

[options]
module.name_mapper='^react-loosely-lazy' ->'<PROJECT_ROOT>/src'
module.name_mapper='^react-resource-router' ->'<PROJECT_ROOT>/src'
# Provides a way to suppress flow errors in the following line.
# Example: // $FlowFixMe: This following line is borked because of reasons.
# Example: // $ExpectError: This following line is correctly ignored by flow.
suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe
suppress_comment= \\(.\\|\n\\)*\\$ExpectError
include_warnings=true
server.max_workers=1

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"eslint-plugin-prettier": "^3.1.3",
"eslint-plugin-react": "^7.20.0",
"eslint-plugin-react-hooks": "^4.0.2",
"flow-bin": "^0.124.0",
"flow-bin": "^0.135.0",
"flow-copy-source": "^2.0.7",
"jest": "^26.0.1",
"madge": "^3.9.0",
Expand Down
35 changes: 16 additions & 19 deletions src/index.js.flow
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
/* eslint-disable no-undef */
/* eslint-disable no-unused-vars */
/* eslint-disable no-undef, no-unused-vars */
// @flow
import type { ComponentType, ElementConfig, Node } from 'react';
import type { BoundActions } from 'react-sweet-state';
import type { BrowserHistory } from 'history/createBrowserHistory';

import type {
HistoryAction,
HistoryBlocker,
BrowserHistory,
HistoryUpdateType,
InvariantRoute,
InvariantRoutes,
LinkProps,
Location,
MatchedInvariantRoute,
MatchedRoute,
MatchParams,
MemoryRouterProps,
Query,
ResourceOptions,
ResourceStoreContext,
Route,
Expand All @@ -26,13 +17,13 @@ import type {
RouteResource,
RouteResourceData,
RouteResourceResponse,
RouteResourceUpdater,
RouterProps,
RouterState,
RouterContext,
RouterSubscriberProps,
Routes,
StaticRouterProps,
CreateRouterContextOptions
CreateRouterContextOptions,
} from './types.js.flow';

export * from './utils.js.flow';
Expand All @@ -55,7 +46,7 @@ declare export function StaticRouter(props: StaticRouterProps): Node;
declare export function ResourceSubscriber(props: {
children: (
resource: RouteResourceResponse & {
update: (data: RouteResourceData | null) => void,
update: (getNewData: RouteResourceUpdater<RouteResourceData>) => void,
refresh: () => void,
}
) => Node,
Expand All @@ -76,7 +67,7 @@ declare export function useResource(
options?: ResourceOptions
): {|
...RouteResourceResponse,
update: (data: RouteResourceData | null) => void,
update: (getNewData: RouteResourceUpdater<RouteResourceData>) => void,
refresh: () => void,
|};
declare export function useRouter(): [
Expand All @@ -87,10 +78,16 @@ declare export function useRouterActions(): BoundActions<RouterActionsType>;
declare export function useResourceStoreContext(): ResourceStoreContext;
declare export function useQueryParam(
paramKey: string
): [string | void, (newValue: string | void, updateType?: HistoryUpdateType) => void];
): [
string | void,
(newValue: string | void, updateType?: HistoryUpdateType) => void
];
declare export function usePathParam(
paramKey: string
): [string | void, (newValue: string | void, updateType?: HistoryUpdateType) => void];
): [
string | void,
(newValue: string | void, updateType?: HistoryUpdateType) => void
];

// Utils
type WithRouterProps = RouteContext & {|
Expand All @@ -103,7 +100,7 @@ declare export function withRouter<
>(
WrappedComponent: Component
): ComponentType<
// $FlowFixMe - $Supertype is deprecated https://github.com/flow-typed/flow-typed/issues/2991
// $FlowFixMe[deprecated-utility] - $Supertype is deprecated https://github.com/flow-typed/flow-typed/issues/2991
$Diff<ElementConfig<$Supertype<Component>>, WithRouterProps>
>;

Expand All @@ -116,7 +113,7 @@ declare export function createLegacyHistory(): BrowserHistory;

declare export function createRouterContext(
route: Route,
options?: CreateRouterContextOptions,
options?: CreateRouterContextOptions
): RouterContext;

/**
Expand Down
23 changes: 11 additions & 12 deletions src/types.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@

import type { Node } from 'react';
import type { Action, BoundActions } from 'react-sweet-state';
import type {
BrowserHistory,
LocationShape as HistoryLocationShape,
MemoryHistory,
} from 'history/createBrowserHistory';

export type LocationShape = {| ...HistoryLocationShape |};
export type BrowserHistory = { ... };
export type MemoryHistory = { ... };
export type LocationShape = { ... };

export type Location = {|
pathname: string,
Expand Down Expand Up @@ -86,6 +83,8 @@ export type ResourceOptions = {
routerContext?: RouterContext,
};

export type RouteResourceUpdater<T: RouteResourceData> = (data: T) => T;

export type InvariantRoute = {
path: string,
exact?: boolean,
Expand Down Expand Up @@ -307,12 +306,12 @@ export type RouterSubscriberProps = {|
|};

export type CreateRouterContextOptions = {
params?: MatchParams;
query?: Query;
basePath?: string;
params?: MatchParams,
query?: Query,
basePath?: string,
};

export type FindRouterContextOptions = {
location: Location;
basePath?: string;
};
location: Location,
basePath?: string,
};
3 changes: 1 addition & 2 deletions src/utils.js.flow
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable no-unused-vars */
// @flow

import type { BrowserHistory } from 'history/createBrowserHistory';

import type {
BrowserHistory,
InvariantRoutes,
MatchedInvariantRoute,
MatchedRoute,
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"react-resource-router": ["src"]
}
},
"include": ["src/**/*", "examples/**/*"]
"include": ["src/**/*", "examples/**/*"],
"exclude": ["**/*.js.flow"]
}

0 comments on commit 3ca7a02

Please sign in to comment.