@pdg/react-hook 2.0.14 → 2.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/effect/index.d.ts +1 -0
- package/dist/effect/useFirstSkipEffect.d.ts +2 -0
- package/dist/eslint-plugin.d.ts +157 -1
- package/dist/eslint-plugin.js +21 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +21 -2
- package/dist/index.js +20 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useFirstSkipEffect';
|
package/dist/eslint-plugin.d.ts
CHANGED
|
@@ -1,2 +1,158 @@
|
|
|
1
|
-
declare const plugin:
|
|
1
|
+
declare const plugin: {
|
|
2
|
+
rules: {
|
|
3
|
+
'exhaustive-deps': {
|
|
4
|
+
create(context: any): {
|
|
5
|
+
CallExpression(node: any): void;
|
|
6
|
+
};
|
|
7
|
+
meta: {
|
|
8
|
+
type: "suggestion";
|
|
9
|
+
docs: {
|
|
10
|
+
description: string;
|
|
11
|
+
recommended: true;
|
|
12
|
+
url: string;
|
|
13
|
+
};
|
|
14
|
+
fixable: "code";
|
|
15
|
+
hasSuggestions: true;
|
|
16
|
+
schema: {
|
|
17
|
+
type: "object";
|
|
18
|
+
additionalProperties: false;
|
|
19
|
+
enableDangerousAutofixThisMayCauseInfiniteLoops: boolean;
|
|
20
|
+
properties: {
|
|
21
|
+
additionalHooks: {
|
|
22
|
+
type: "string";
|
|
23
|
+
};
|
|
24
|
+
enableDangerousAutofixThisMayCauseInfiniteLoops: {
|
|
25
|
+
type: "boolean";
|
|
26
|
+
};
|
|
27
|
+
experimental_autoDependenciesHooks: {
|
|
28
|
+
type: "array";
|
|
29
|
+
items: {
|
|
30
|
+
type: "string";
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
requireExplicitEffectDeps: {
|
|
34
|
+
type: "boolean";
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
}[];
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
'rules-of-hooks': {
|
|
41
|
+
meta: {
|
|
42
|
+
type: "problem";
|
|
43
|
+
docs: {
|
|
44
|
+
description: string;
|
|
45
|
+
recommended: true;
|
|
46
|
+
url: string;
|
|
47
|
+
};
|
|
48
|
+
schema: {
|
|
49
|
+
type: "object";
|
|
50
|
+
additionalProperties: false;
|
|
51
|
+
properties: {
|
|
52
|
+
additionalHooks: {
|
|
53
|
+
type: "string";
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
}[];
|
|
57
|
+
};
|
|
58
|
+
create(context: import("eslint").Rule.RuleContext): {
|
|
59
|
+
"*"(node: any): void;
|
|
60
|
+
"*:exit"(node: any): void;
|
|
61
|
+
CallExpression(node: import("estree").CallExpression & import("eslint").Rule.NodeParentExtension): void;
|
|
62
|
+
Identifier(node: import("estree").Identifier & import("eslint").Rule.NodeParentExtension): void;
|
|
63
|
+
"CallExpression:exit"(node: import("estree").CallExpression & import("eslint").Rule.NodeParentExtension): void;
|
|
64
|
+
FunctionDeclaration(node: import("estree").FunctionDeclaration & import("eslint").Rule.NodeParentExtension): void;
|
|
65
|
+
ArrowFunctionExpression(node: import("estree").ArrowFunctionExpression & import("eslint").Rule.NodeParentExtension): void;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
configs: {
|
|
70
|
+
recommended: {
|
|
71
|
+
plugins: string[];
|
|
72
|
+
rules: {
|
|
73
|
+
'@pdg/react-hooks/rules-of-hooks': string;
|
|
74
|
+
'@pdg/react-hooks/exhaustive-deps': string;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
flat: {
|
|
78
|
+
recommended: {
|
|
79
|
+
plugins: {
|
|
80
|
+
'@pdg/react-hooks': {
|
|
81
|
+
rules: {
|
|
82
|
+
'exhaustive-deps': {
|
|
83
|
+
create(context: any): {
|
|
84
|
+
CallExpression(node: any): void;
|
|
85
|
+
};
|
|
86
|
+
meta: {
|
|
87
|
+
type: "suggestion";
|
|
88
|
+
docs: {
|
|
89
|
+
description: string;
|
|
90
|
+
recommended: true;
|
|
91
|
+
url: string;
|
|
92
|
+
};
|
|
93
|
+
fixable: "code";
|
|
94
|
+
hasSuggestions: true;
|
|
95
|
+
schema: {
|
|
96
|
+
type: "object";
|
|
97
|
+
additionalProperties: false;
|
|
98
|
+
enableDangerousAutofixThisMayCauseInfiniteLoops: boolean;
|
|
99
|
+
properties: {
|
|
100
|
+
additionalHooks: {
|
|
101
|
+
type: "string";
|
|
102
|
+
};
|
|
103
|
+
enableDangerousAutofixThisMayCauseInfiniteLoops: {
|
|
104
|
+
type: "boolean";
|
|
105
|
+
};
|
|
106
|
+
experimental_autoDependenciesHooks: {
|
|
107
|
+
type: "array";
|
|
108
|
+
items: {
|
|
109
|
+
type: "string";
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
requireExplicitEffectDeps: {
|
|
113
|
+
type: "boolean";
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
}[];
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
'rules-of-hooks': {
|
|
120
|
+
meta: {
|
|
121
|
+
type: "problem";
|
|
122
|
+
docs: {
|
|
123
|
+
description: string;
|
|
124
|
+
recommended: true;
|
|
125
|
+
url: string;
|
|
126
|
+
};
|
|
127
|
+
schema: {
|
|
128
|
+
type: "object";
|
|
129
|
+
additionalProperties: false;
|
|
130
|
+
properties: {
|
|
131
|
+
additionalHooks: {
|
|
132
|
+
type: "string";
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
}[];
|
|
136
|
+
};
|
|
137
|
+
create(context: import("eslint").Rule.RuleContext): {
|
|
138
|
+
"*"(node: any): void;
|
|
139
|
+
"*:exit"(node: any): void;
|
|
140
|
+
CallExpression(node: import("estree").CallExpression & import("eslint").Rule.NodeParentExtension): void;
|
|
141
|
+
Identifier(node: import("estree").Identifier & import("eslint").Rule.NodeParentExtension): void;
|
|
142
|
+
"CallExpression:exit"(node: import("estree").CallExpression & import("eslint").Rule.NodeParentExtension): void;
|
|
143
|
+
FunctionDeclaration(node: import("estree").FunctionDeclaration & import("eslint").Rule.NodeParentExtension): void;
|
|
144
|
+
ArrowFunctionExpression(node: import("estree").ArrowFunctionExpression & import("eslint").Rule.NodeParentExtension): void;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
rules: {
|
|
151
|
+
'@pdg/react-hooks/rules-of-hooks': string;
|
|
152
|
+
'@pdg/react-hooks/exhaustive-deps': string;
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
};
|
|
157
|
+
};
|
|
2
158
|
export default plugin;
|
package/dist/eslint-plugin.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import reactHooksPlugin from 'eslint-plugin-react-hooks';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const pluginRules = {
|
|
4
4
|
rules: {
|
|
5
5
|
'exhaustive-deps': Object.assign(Object.assign({}, reactHooksPlugin.rules['exhaustive-deps']), { create(context) {
|
|
6
6
|
const originalRule = reactHooksPlugin.rules['exhaustive-deps'].create(context);
|
|
7
7
|
return Object.assign(Object.assign({}, originalRule), { CallExpression(node) {
|
|
8
8
|
const callbackName = node.callee.name;
|
|
9
|
+
/** useChanged */
|
|
9
10
|
if (callbackName === 'useChanged') {
|
|
10
11
|
const depsNode = node.arguments[0];
|
|
11
12
|
if (!depsNode || depsNode.type !== 'ArrayExpression') {
|
|
12
13
|
context.report({
|
|
13
|
-
node: node.callee,
|
|
14
|
+
node: node.callee,
|
|
14
15
|
message: 'useChanged 훅의 첫 번째 인자는 반드시 배열 리터럴(예: [a, b]) 형태여야 합니다.',
|
|
15
16
|
});
|
|
16
17
|
return;
|
|
@@ -33,13 +34,25 @@ const plugin = {
|
|
|
33
34
|
const fakeNode = Object.assign(Object.assign({}, node), { arguments: [fakeCallback, depsNode] });
|
|
34
35
|
return originalRule.CallExpression(fakeNode);
|
|
35
36
|
}
|
|
37
|
+
/** useFirstSkipEffect */
|
|
38
|
+
if (callbackName === 'useFirstSkipEffect') {
|
|
39
|
+
const deps = node.arguments[1];
|
|
40
|
+
if (!deps || deps.type !== 'ArrayExpression') {
|
|
41
|
+
context.report({
|
|
42
|
+
node: node.callee,
|
|
43
|
+
message: 'useFirstSkipEffect 훅의 두 번째 인자는 반드시 배열 리터럴(예: [a, b]) 형태여야 합니다.',
|
|
44
|
+
});
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
return originalRule.CallExpression(node);
|
|
48
|
+
}
|
|
36
49
|
return originalRule.CallExpression(node);
|
|
37
50
|
} });
|
|
38
51
|
} }),
|
|
39
52
|
'rules-of-hooks': reactHooksPlugin.rules['rules-of-hooks'],
|
|
40
53
|
},
|
|
41
54
|
};
|
|
42
|
-
|
|
55
|
+
const plugConfig = {
|
|
43
56
|
recommended: {
|
|
44
57
|
plugins: ['@pdg/react-hooks'],
|
|
45
58
|
rules: {
|
|
@@ -50,7 +63,7 @@ plugin.config = {
|
|
|
50
63
|
flat: {
|
|
51
64
|
recommended: {
|
|
52
65
|
plugins: {
|
|
53
|
-
'@pdg/react-hooks':
|
|
66
|
+
'@pdg/react-hooks': pluginRules,
|
|
54
67
|
},
|
|
55
68
|
rules: {
|
|
56
69
|
'@pdg/react-hooks/rules-of-hooks': 'error',
|
|
@@ -59,5 +72,9 @@ plugin.config = {
|
|
|
59
72
|
},
|
|
60
73
|
},
|
|
61
74
|
};
|
|
75
|
+
const plugin = {
|
|
76
|
+
rules: pluginRules.rules,
|
|
77
|
+
configs: plugConfig,
|
|
78
|
+
};
|
|
62
79
|
|
|
63
80
|
export { plugin as default };
|
package/dist/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useState,useRef,useEffect,useLayoutEffect,useImperativeHandle}from'react';import {c}from'react/compiler-runtime';function _arrayLikeToArray(r, a) {
|
|
1
|
+
import {useState,useEffectEvent,useRef,useEffect,useLayoutEffect,useImperativeHandle}from'react';import {c}from'react/compiler-runtime';function _arrayLikeToArray(r, a) {
|
|
2
2
|
(null == a || a > r.length) && (a = r.length);
|
|
3
3
|
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
4
4
|
return n;
|
|
@@ -68,6 +68,25 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
68
68
|
setPrevValues(deps);
|
|
69
69
|
}
|
|
70
70
|
return changed;
|
|
71
|
+
};var useFirstSkipEffect = function useFirstSkipEffect(effectEventCallback, deps) {
|
|
72
|
+
var $ = c(2);
|
|
73
|
+
var effectEvent = useEffectEvent(effectEventCallback);
|
|
74
|
+
var firstSkipRef = useRef(true);
|
|
75
|
+
var t0;
|
|
76
|
+
if ($[0] !== effectEvent) {
|
|
77
|
+
t0 = function t0() {
|
|
78
|
+
if (firstSkipRef.current) {
|
|
79
|
+
firstSkipRef.current = false;
|
|
80
|
+
} else {
|
|
81
|
+
return effectEvent();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
$[0] = effectEvent;
|
|
85
|
+
$[1] = t0;
|
|
86
|
+
} else {
|
|
87
|
+
t0 = $[1];
|
|
88
|
+
}
|
|
89
|
+
useEffect(t0, deps);
|
|
71
90
|
};function useMountedRef(t0) {
|
|
72
91
|
var $ = c(2);
|
|
73
92
|
var initialValue = t0 === undefined ? true : t0;
|
|
@@ -228,4 +247,4 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
228
247
|
t3 = $[7];
|
|
229
248
|
}
|
|
230
249
|
useEffect(t2, t3);
|
|
231
|
-
}export{clearIntervalRef,clearTimeoutRef,useAutoUpdateRef,useChanged,useForwardRef,useIntervalRef,useMountedRef,useTimeoutRef};
|
|
250
|
+
}export{clearIntervalRef,clearTimeoutRef,useAutoUpdateRef,useChanged,useFirstSkipEffect,useForwardRef,useIntervalRef,useMountedRef,useTimeoutRef};
|
package/dist/index.js
CHANGED
|
@@ -68,6 +68,25 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
68
68
|
setPrevValues(deps);
|
|
69
69
|
}
|
|
70
70
|
return changed;
|
|
71
|
+
};var useFirstSkipEffect = function useFirstSkipEffect(effectEventCallback, deps) {
|
|
72
|
+
var $ = compilerRuntime.c(2);
|
|
73
|
+
var effectEvent = react.useEffectEvent(effectEventCallback);
|
|
74
|
+
var firstSkipRef = react.useRef(true);
|
|
75
|
+
var t0;
|
|
76
|
+
if ($[0] !== effectEvent) {
|
|
77
|
+
t0 = function t0() {
|
|
78
|
+
if (firstSkipRef.current) {
|
|
79
|
+
firstSkipRef.current = false;
|
|
80
|
+
} else {
|
|
81
|
+
return effectEvent();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
$[0] = effectEvent;
|
|
85
|
+
$[1] = t0;
|
|
86
|
+
} else {
|
|
87
|
+
t0 = $[1];
|
|
88
|
+
}
|
|
89
|
+
react.useEffect(t0, deps);
|
|
71
90
|
};function useMountedRef(t0) {
|
|
72
91
|
var $ = compilerRuntime.c(2);
|
|
73
92
|
var initialValue = t0 === undefined ? true : t0;
|
|
@@ -228,4 +247,4 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
228
247
|
t3 = $[7];
|
|
229
248
|
}
|
|
230
249
|
react.useEffect(t2, t3);
|
|
231
|
-
}exports.clearIntervalRef=clearIntervalRef;exports.clearTimeoutRef=clearTimeoutRef;exports.useAutoUpdateRef=useAutoUpdateRef;exports.useChanged=useChanged;exports.useForwardRef=useForwardRef;exports.useIntervalRef=useIntervalRef;exports.useMountedRef=useMountedRef;exports.useTimeoutRef=useTimeoutRef;
|
|
250
|
+
}exports.clearIntervalRef=clearIntervalRef;exports.clearTimeoutRef=clearTimeoutRef;exports.useAutoUpdateRef=useAutoUpdateRef;exports.useChanged=useChanged;exports.useFirstSkipEffect=useFirstSkipEffect;exports.useForwardRef=useForwardRef;exports.useIntervalRef=useIntervalRef;exports.useMountedRef=useMountedRef;exports.useTimeoutRef=useTimeoutRef;
|
package/package.json
CHANGED