Skip to content

Commit 04518b3

Browse files
committed
Add types file for common types
1 parent 265a4d8 commit 04518b3

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

src/Query.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
/* @flow */
22
// Add `strict` once Dispatch type is added
33

4-
import type { JSONAPIResource, JSONAPIResourceIdentifier } from 'json-api';
4+
import type { JSONAPIResource } from 'json-api';
55
import React, { type Node, PureComponent } from 'react';
66
import { connect } from 'react-redux';
77
import { readEndpoint } from 'redux-json-api';
8+
import type { Links, CachedResponse } from './types';
89
import DataSet from './DataSet';
910
import QueryCache from './QueryCache';
1011

11-
type Link = {|
12-
load: () => void,
13-
|};
14-
15-
type Links = { [string]: Link };
16-
1712
type Refetch = () => void;
1813

19-
export type StoredResponse = {|
20-
links: Links,
21-
resourceIds: Array<JSONAPIResourceIdentifier>,
22-
|};
23-
2414
type RenderProp = ({
2515
error?: Error,
2616
loading: boolean,
@@ -39,7 +29,7 @@ type Props = {|
3929
type State = {|
4030
error?: Error,
4131
loading: boolean,
42-
...StoredResponse,
32+
...CachedResponse,
4333
|};
4434

4535
export class Query extends PureComponent<Props, State> {
@@ -58,7 +48,7 @@ export class Query extends PureComponent<Props, State> {
5848
this.loadEndpoint(this.props.endpoint);
5949
}
6050

61-
setResponse = ({ resourceIds, links }: StoredResponse) => {
51+
setResponse = ({ resourceIds, links }: CachedResponse) => {
6252
this.setState({
6353
resourceIds,
6454
links,

src/QueryCache.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* @flow strict-local */
22

3-
import type { StoredResponse } from './Query';
3+
import type { CachedResponse } from './types';
44

55
export default class QueryCache {
6-
static cachedEndpoints: Map<string, StoredResponse> = new Map();
6+
static cachedEndpoints: Map<string, CachedResponse> = new Map();
77

8-
static cacheEndpoint(endpoint: string, response: StoredResponse) {
8+
static cacheEndpoint(endpoint: string, response: CachedResponse) {
99
QueryCache.cachedEndpoints.set(endpoint, response);
1010
}
1111

src/types.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* @flow strict */
2+
3+
import type { JSONAPIResourceIdentifier } from 'json-api';
4+
5+
type Link = {|
6+
load: () => void,
7+
|};
8+
9+
export type Links = { [string]: Link };
10+
11+
export type CachedResponse = {|
12+
links: Links,
13+
resourceIds: Array<JSONAPIResourceIdentifier>,
14+
|};

0 commit comments

Comments
 (0)