Skip to content

Commit cd1c983

Browse files
committed
Remove type variable from PrimitiveDep.
1 parent d801d9f commit cd1c983

File tree

7 files changed

+41
-108
lines changed

7 files changed

+41
-108
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ jobs:
1515
cache: yarn
1616
- run: yarn install
1717
- run: yarn build
18+
- run: yarn gen-flow
1819
- run: yarn test
1920
- run: yarn run check-git-clean

dist/index.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@
33
Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
6-
Object.defineProperty(exports, "idExtraDep", {
7-
enumerable: true,
8-
get: function get() {
9-
return _useExtraDeps.idExtraDep;
10-
}
11-
});
12-
Object.defineProperty(exports, "isEqualExtraDep", {
13-
enumerable: true,
14-
get: function get() {
15-
return _useExtraDeps.isEqualExtraDep;
16-
}
17-
});
186
Object.defineProperty(exports, "unCallbackFn", {
197
enumerable: true,
208
get: function get() {

dist/index.js.flow

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
// @flow
2+
13
export {
24
unCallbackFn,
35
unsafeMkCallbackFn,
46
useExtraDeps,
5-
idExtraDep,
6-
isEqualExtraDep,
77
} from "./use-extra-deps";

dist/use-extra-deps/index.js

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
77
Object.defineProperty(exports, "__esModule", {
88
value: true
99
});
10-
exports.unCallbackFn = exports.isEqualExtraDep = exports.idExtraDep = void 0;
10+
exports.unCallbackFn = void 0;
1111
exports.unsafeMkCallbackFn = unsafeMkCallbackFn;
1212
exports.useExtraDeps = useExtraDeps;
1313

@@ -50,18 +50,18 @@ function unsafeMkCallbackFn(f) {
5050
return f;
5151
}
5252

53-
// Hook used to help avoid pitfalls surrounding misuse of objects and arrays in the deps of
54-
// `useEffect` et. al.
53+
// Hook used to help avoid pitfalls surrounding misuse of objects and arrays in
54+
// the deps of `useEffect` et. al.
5555
//
56-
// By only allowing `PrimitiveDep`s in the `deps` array and forcing functions and non-primitives
57-
// through `extraDeps`, we can ensure that we are not doing naive reference equality like React
58-
// does for the `deps` array.
56+
// By only allowing `PrimitiveDep`s in the `deps` array and forcing functions
57+
// and non-primitives through `extraDeps`, we can ensure that we are not doing
58+
// naive reference equality like React does for the `deps` array.
5959
//
6060
// See `useSafeEffect` for usage of this hook
6161
//
62-
// Returns an object based upon deps and extraDeps:
63-
// { allDeps: An array that is suitable to use as a deps array for things like `useEffect`
64-
// , extraDepValues: An object that has the same keys as extraDeps but contains their plain values
62+
// Returns an object based upon deps and extraDeps: { allDeps: An array that is
63+
// suitable to use as a deps array for things like `useEffect` , extraDepValues:
64+
// An object that has the same keys as extraDeps but contains their plain values
6565
// }
6666
//
6767
function useExtraDeps(deps, extraDeps) {
@@ -100,26 +100,4 @@ function useExtraDeps(deps, extraDeps) {
100100
return value;
101101
})), fns)
102102
};
103-
}
104-
105-
var idExtraDep = function idExtraDep(value) {
106-
return {
107-
value: value,
108-
comparator: function comparator(a, b) {
109-
return a.id === b.id;
110-
}
111-
};
112-
};
113-
114-
exports.idExtraDep = idExtraDep;
115-
116-
var isEqualExtraDep = function isEqualExtraDep(value) {
117-
return {
118-
value: value,
119-
comparator: function comparator(a, b) {
120-
return (0, _isEqual["default"])(a, b);
121-
}
122-
};
123-
};
124-
125-
exports.isEqualExtraDep = isEqualExtraDep;
103+
}

dist/use-extra-deps/index.js.flow

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,11 @@ import mapValues from "lodash/mapValues";
88
import values from "lodash/values";
99
import isEqual from "lodash/isEqual";
1010

11-
export type PrimitiveLangDep = boolean | string | number | null | void | symbol;
12-
1311
// Dependencies that are safe to use in the normal `useEffect` deps array
14-
//
15-
// `PrimitiveDep` is a generic type. Typically usage is to bind the type
16-
// variable `PrimitiveDomainDep` to opaque types that wrap primitives.
17-
export type PrimitiveDep<PrimitiveDomainDep> =
18-
| PrimitiveLangDep
19-
| PrimitiveDomainDep;
12+
export type PrimitiveDep = boolean | string | number | null | void | symbol;
2013

21-
// Wrapper around a function that has been wrapped in `useSafeCallback`. This type is here to avoid
22-
// cyclical dependencies.
14+
// Wrapper around a function that has been wrapped in `useSafeCallback`. This
15+
// type is here to avoid cyclical dependencies.
2316
export opaque type CallbackFn<F> = F;
2417

2518
export const unCallbackFn = <F>(fn: CallbackFn<F>): F => fn;
@@ -35,22 +28,22 @@ export type ExtraDeps<V> =
3528
| {| value: V, comparator: (a: V, b: V) => boolean |}
3629
| CallbackFn<V>;
3730

38-
// Hook used to help avoid pitfalls surrounding misuse of objects and arrays in the deps of
39-
// `useEffect` et. al.
31+
// Hook used to help avoid pitfalls surrounding misuse of objects and arrays in
32+
// the deps of `useEffect` et. al.
4033
//
41-
// By only allowing `PrimitiveDep`s in the `deps` array and forcing functions and non-primitives
42-
// through `extraDeps`, we can ensure that we are not doing naive reference equality like React
43-
// does for the `deps` array.
34+
// By only allowing `PrimitiveDep`s in the `deps` array and forcing functions
35+
// and non-primitives through `extraDeps`, we can ensure that we are not doing
36+
// naive reference equality like React does for the `deps` array.
4437
//
4538
// See `useSafeEffect` for usage of this hook
4639
//
47-
// Returns an object based upon deps and extraDeps:
48-
// { allDeps: An array that is suitable to use as a deps array for things like `useEffect`
49-
// , extraDepValues: An object that has the same keys as extraDeps but contains their plain values
40+
// Returns an object based upon deps and extraDeps: { allDeps: An array that is
41+
// suitable to use as a deps array for things like `useEffect` , extraDepValues:
42+
// An object that has the same keys as extraDeps but contains their plain values
5043
// }
5144
//
52-
export function useExtraDeps<S: { [key: string]: any }, PrimitiveDomainDep>(
53-
deps: $ReadOnlyArray<PrimitiveDep<PrimitiveDomainDep>>,
45+
export function useExtraDeps<S: { [key: string]: any }>(
46+
deps: $ReadOnlyArray<PrimitiveDep>,
5447
extraDeps: S
5548
): {|
5649
allDeps: $ReadOnlyArray<any>,
@@ -86,13 +79,3 @@ export function useExtraDeps<S: { [key: string]: any }, PrimitiveDomainDep>(
8679
extraDepValues: { ...mapValues(nonFns, ({ value }) => value), ...fns },
8780
};
8881
}
89-
90-
export const idExtraDep = <V: { id: string }>(value: V): ExtraDeps<V> => ({
91-
value,
92-
comparator: (a, b) => a.id === b.id,
93-
});
94-
95-
export const isEqualExtraDep = <V>(value: V): ExtraDeps<V> => ({
96-
value,
97-
comparator: (a: V, b: V): boolean => isEqual(a, b),
98-
});

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
// @flow
2+
13
export {
24
unCallbackFn,
35
unsafeMkCallbackFn,
46
useExtraDeps,
5-
idExtraDep,
6-
isEqualExtraDep,
77
} from "./use-extra-deps";

src/use-extra-deps/index.js

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,11 @@ import mapValues from "lodash/mapValues";
88
import values from "lodash/values";
99
import isEqual from "lodash/isEqual";
1010

11-
export type PrimitiveLangDep = boolean | string | number | null | void | symbol;
12-
1311
// Dependencies that are safe to use in the normal `useEffect` deps array
14-
//
15-
// `PrimitiveDep` is a generic type. Typically usage is to bind the type
16-
// variable `PrimitiveDomainDep` to opaque types that wrap primitives.
17-
export type PrimitiveDep<PrimitiveDomainDep> =
18-
| PrimitiveLangDep
19-
| PrimitiveDomainDep;
12+
export type PrimitiveDep = boolean | string | number | null | void | symbol;
2013

21-
// Wrapper around a function that has been wrapped in `useSafeCallback`. This type is here to avoid
22-
// cyclical dependencies.
14+
// Wrapper around a function that has been wrapped in `useSafeCallback`. This
15+
// type is here to avoid cyclical dependencies.
2316
export opaque type CallbackFn<F> = F;
2417

2518
export const unCallbackFn = <F>(fn: CallbackFn<F>): F => fn;
@@ -35,22 +28,22 @@ export type ExtraDeps<V> =
3528
| {| value: V, comparator: (a: V, b: V) => boolean |}
3629
| CallbackFn<V>;
3730

38-
// Hook used to help avoid pitfalls surrounding misuse of objects and arrays in the deps of
39-
// `useEffect` et. al.
31+
// Hook used to help avoid pitfalls surrounding misuse of objects and arrays in
32+
// the deps of `useEffect` et. al.
4033
//
41-
// By only allowing `PrimitiveDep`s in the `deps` array and forcing functions and non-primitives
42-
// through `extraDeps`, we can ensure that we are not doing naive reference equality like React
43-
// does for the `deps` array.
34+
// By only allowing `PrimitiveDep`s in the `deps` array and forcing functions
35+
// and non-primitives through `extraDeps`, we can ensure that we are not doing
36+
// naive reference equality like React does for the `deps` array.
4437
//
4538
// See `useSafeEffect` for usage of this hook
4639
//
47-
// Returns an object based upon deps and extraDeps:
48-
// { allDeps: An array that is suitable to use as a deps array for things like `useEffect`
49-
// , extraDepValues: An object that has the same keys as extraDeps but contains their plain values
40+
// Returns an object based upon deps and extraDeps: { allDeps: An array that is
41+
// suitable to use as a deps array for things like `useEffect` , extraDepValues:
42+
// An object that has the same keys as extraDeps but contains their plain values
5043
// }
5144
//
52-
export function useExtraDeps<S: { [key: string]: any }, PrimitiveDomainDep>(
53-
deps: $ReadOnlyArray<PrimitiveDep<PrimitiveDomainDep>>,
45+
export function useExtraDeps<S: { [key: string]: any }>(
46+
deps: $ReadOnlyArray<PrimitiveDep>,
5447
extraDeps: S
5548
): {|
5649
allDeps: $ReadOnlyArray<any>,
@@ -86,13 +79,3 @@ export function useExtraDeps<S: { [key: string]: any }, PrimitiveDomainDep>(
8679
extraDepValues: { ...mapValues(nonFns, ({ value }) => value), ...fns },
8780
};
8881
}
89-
90-
export const idExtraDep = <V: { id: string }>(value: V): ExtraDeps<V> => ({
91-
value,
92-
comparator: (a, b) => a.id === b.id,
93-
});
94-
95-
export const isEqualExtraDep = <V>(value: V): ExtraDeps<V> => ({
96-
value,
97-
comparator: (a: V, b: V): boolean => isEqual(a, b),
98-
});

0 commit comments

Comments
 (0)