@wordpress/compose 5.15.2 → 5.16.0

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.
Files changed (71) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +50 -5
  3. package/build/higher-order/compose.js +5 -4
  4. package/build/higher-order/compose.js.map +1 -1
  5. package/build/higher-order/pipe.js +93 -0
  6. package/build/higher-order/pipe.js.map +1 -0
  7. package/build/hooks/use-debounce/index.js +11 -10
  8. package/build/hooks/use-debounce/index.js.map +1 -1
  9. package/build/hooks/use-disabled/index.js +3 -1
  10. package/build/hooks/use-disabled/index.js.map +1 -1
  11. package/build/hooks/use-drop-zone/index.js +2 -0
  12. package/build/hooks/use-drop-zone/index.js.map +1 -1
  13. package/build/hooks/use-fixed-window-list/index.js +5 -5
  14. package/build/hooks/use-fixed-window-list/index.js.map +1 -1
  15. package/build/hooks/use-instance-id/index.js +22 -20
  16. package/build/hooks/use-instance-id/index.js.map +1 -1
  17. package/build/index.js +23 -0
  18. package/build/index.js.map +1 -1
  19. package/build/index.native.js +23 -0
  20. package/build/index.native.js.map +1 -1
  21. package/build/utils/debounce/index.js +230 -0
  22. package/build/utils/debounce/index.js.map +1 -0
  23. package/build-module/higher-order/compose.js +4 -3
  24. package/build-module/higher-order/compose.js.map +1 -1
  25. package/build-module/higher-order/pipe.js +85 -0
  26. package/build-module/higher-order/pipe.js.map +1 -0
  27. package/build-module/hooks/use-debounce/index.js +10 -9
  28. package/build-module/hooks/use-debounce/index.js.map +1 -1
  29. package/build-module/hooks/use-disabled/index.js +3 -2
  30. package/build-module/hooks/use-disabled/index.js.map +1 -1
  31. package/build-module/hooks/use-drop-zone/index.js +2 -0
  32. package/build-module/hooks/use-drop-zone/index.js.map +1 -1
  33. package/build-module/hooks/use-fixed-window-list/index.js +5 -5
  34. package/build-module/hooks/use-fixed-window-list/index.js.map +1 -1
  35. package/build-module/hooks/use-instance-id/index.js +20 -19
  36. package/build-module/hooks/use-instance-id/index.js.map +1 -1
  37. package/build-module/index.js +5 -2
  38. package/build-module/index.js.map +1 -1
  39. package/build-module/index.native.js +5 -2
  40. package/build-module/index.native.js.map +1 -1
  41. package/build-module/utils/debounce/index.js +221 -0
  42. package/build-module/utils/debounce/index.js.map +1 -0
  43. package/build-types/higher-order/compose.d.ts +2 -5
  44. package/build-types/higher-order/compose.d.ts.map +1 -1
  45. package/build-types/higher-order/pipe.d.ts +61 -0
  46. package/build-types/higher-order/pipe.d.ts.map +1 -0
  47. package/build-types/hooks/use-debounce/index.d.ts +6 -6
  48. package/build-types/hooks/use-debounce/index.d.ts.map +1 -1
  49. package/build-types/hooks/use-disabled/index.d.ts.map +1 -1
  50. package/build-types/hooks/use-drop-zone/index.d.ts.map +1 -1
  51. package/build-types/hooks/use-instance-id/index.d.ts +11 -6
  52. package/build-types/hooks/use-instance-id/index.d.ts.map +1 -1
  53. package/build-types/index.d.ts +2 -0
  54. package/build-types/utils/debounce/index.d.ts +104 -0
  55. package/build-types/utils/debounce/index.d.ts.map +1 -0
  56. package/package.json +8 -8
  57. package/src/higher-order/compose.ts +5 -3
  58. package/src/higher-order/pipe.ts +76 -0
  59. package/src/higher-order/test/compose.ts +39 -0
  60. package/src/higher-order/test/pipe.ts +37 -0
  61. package/src/hooks/use-debounce/index.js +11 -9
  62. package/src/hooks/use-disabled/index.js +3 -2
  63. package/src/hooks/use-drop-zone/index.js +2 -0
  64. package/src/hooks/use-fixed-window-list/index.js +5 -5
  65. package/src/hooks/use-instance-id/index.ts +59 -0
  66. package/src/index.js +4 -1
  67. package/src/index.native.js +4 -1
  68. package/src/utils/debounce/index.ts +260 -0
  69. package/src/utils/debounce/test/index.ts +367 -0
  70. package/tsconfig.tsbuildinfo +1 -1
  71. package/src/hooks/use-instance-id/index.js +0 -42
@@ -0,0 +1,221 @@
1
+ /**
2
+ * Parts of this source were derived and modified from lodash,
3
+ * released under the MIT license.
4
+ *
5
+ * https://github.com/lodash/lodash
6
+ *
7
+ * Copyright JS Foundation and other contributors <https://js.foundation/>
8
+ *
9
+ * Based on Underscore.js, copyright Jeremy Ashkenas,
10
+ * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
11
+ *
12
+ * This software consists of voluntary contributions made by many
13
+ * individuals. For exact contribution history, see the revision history
14
+ * available at https://github.com/lodash/lodash
15
+ *
16
+ * The following license applies to all parts of this software except as
17
+ * documented below:
18
+ *
19
+ * ====
20
+ *
21
+ * Permission is hereby granted, free of charge, to any person obtaining
22
+ * a copy of this software and associated documentation files (the
23
+ * "Software"), to deal in the Software without restriction, including
24
+ * without limitation the rights to use, copy, modify, merge, publish,
25
+ * distribute, sublicense, and/or sell copies of the Software, and to
26
+ * permit persons to whom the Software is furnished to do so, subject to
27
+ * the following conditions:
28
+ *
29
+ * The above copyright notice and this permission notice shall be
30
+ * included in all copies or substantial portions of the Software.
31
+ *
32
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
+ */
40
+
41
+ /**
42
+ * A simplified and properly typed version of lodash's `debounce`, that
43
+ * always uses timers instead of sometimes using rAF.
44
+ *
45
+ * Creates a debounced function that delays invoking `func` until after `wait`
46
+ * milliseconds have elapsed since the last time the debounced function was
47
+ * invoked. The debounced function comes with a `cancel` method to cancel delayed
48
+ * `func` invocations and a `flush` method to immediately invoke them. Provide
49
+ * `options` to indicate whether `func` should be invoked on the leading and/or
50
+ * trailing edge of the `wait` timeout. The `func` is invoked with the last
51
+ * arguments provided to the debounced function. Subsequent calls to the debounced
52
+ * function return the result of the last `func` invocation.
53
+ *
54
+ * **Note:** If `leading` and `trailing` options are `true`, `func` is
55
+ * invoked on the trailing edge of the timeout only if the debounced function
56
+ * is invoked more than once during the `wait` timeout.
57
+ *
58
+ * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
59
+ * until the next tick, similar to `setTimeout` with a timeout of `0`.
60
+ *
61
+ * @param {Function} func The function to debounce.
62
+ * @param {number} wait The number of milliseconds to delay.
63
+ * @param {Partial< DebounceOptions >} options The options object.
64
+ * @param {boolean} options.leading Specify invoking on the leading edge of the timeout.
65
+ * @param {number} options.maxWait The maximum time `func` is allowed to be delayed before it's invoked.
66
+ * @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.
67
+ *
68
+ * @return Returns the new debounced function.
69
+ */
70
+ export const debounce = (func, wait, options) => {
71
+ let lastArgs;
72
+ let lastThis;
73
+ let maxWait = 0;
74
+ let result;
75
+ let timerId;
76
+ let lastCallTime;
77
+ let lastInvokeTime = 0;
78
+ let leading = false;
79
+ let maxing = false;
80
+ let trailing = true;
81
+
82
+ if (options) {
83
+ leading = !!options.leading;
84
+ maxing = 'maxWait' in options;
85
+
86
+ if (options.maxWait !== undefined) {
87
+ maxWait = Math.max(options.maxWait, wait);
88
+ }
89
+
90
+ trailing = 'trailing' in options ? !!options.trailing : trailing;
91
+ }
92
+
93
+ function invokeFunc(time) {
94
+ const args = lastArgs;
95
+ const thisArg = lastThis;
96
+ lastArgs = undefined;
97
+ lastThis = undefined;
98
+ lastInvokeTime = time;
99
+ result = func.apply(thisArg, args);
100
+ return result;
101
+ }
102
+
103
+ function startTimer(pendingFunc, waitTime) {
104
+ timerId = setTimeout(pendingFunc, waitTime);
105
+ }
106
+
107
+ function cancelTimer() {
108
+ if (timerId !== undefined) {
109
+ clearTimeout(timerId);
110
+ }
111
+ }
112
+
113
+ function leadingEdge(time) {
114
+ // Reset any `maxWait` timer.
115
+ lastInvokeTime = time; // Start the timer for the trailing edge.
116
+
117
+ startTimer(timerExpired, wait); // Invoke the leading edge.
118
+
119
+ return leading ? invokeFunc(time) : result;
120
+ }
121
+
122
+ function getTimeSinceLastCall(time) {
123
+ return time - (lastCallTime || 0);
124
+ }
125
+
126
+ function remainingWait(time) {
127
+ const timeSinceLastCall = getTimeSinceLastCall(time);
128
+ const timeSinceLastInvoke = time - lastInvokeTime;
129
+ const timeWaiting = wait - timeSinceLastCall;
130
+ return maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
131
+ }
132
+
133
+ function shouldInvoke(time) {
134
+ const timeSinceLastCall = getTimeSinceLastCall(time);
135
+ const timeSinceLastInvoke = time - lastInvokeTime; // Either this is the first call, activity has stopped and we're at the
136
+ // trailing edge, the system time has gone backwards and we're treating
137
+ // it as the trailing edge, or we've hit the `maxWait` limit.
138
+
139
+ return lastCallTime === undefined || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
140
+ }
141
+
142
+ function timerExpired() {
143
+ const time = Date.now();
144
+
145
+ if (shouldInvoke(time)) {
146
+ return trailingEdge(time);
147
+ } // Restart the timer.
148
+
149
+
150
+ startTimer(timerExpired, remainingWait(time));
151
+ return undefined;
152
+ }
153
+
154
+ function clearTimer() {
155
+ timerId = undefined;
156
+ }
157
+
158
+ function trailingEdge(time) {
159
+ clearTimer(); // Only invoke if we have `lastArgs` which means `func` has been
160
+ // debounced at least once.
161
+
162
+ if (trailing && lastArgs) {
163
+ return invokeFunc(time);
164
+ }
165
+
166
+ lastArgs = lastThis = undefined;
167
+ return result;
168
+ }
169
+
170
+ function cancel() {
171
+ cancelTimer();
172
+ lastInvokeTime = 0;
173
+ clearTimer();
174
+ lastArgs = lastCallTime = lastThis = undefined;
175
+ }
176
+
177
+ function flush() {
178
+ return pending() ? trailingEdge(Date.now()) : result;
179
+ }
180
+
181
+ function pending() {
182
+ return timerId !== undefined;
183
+ }
184
+
185
+ function debounced() {
186
+ const time = Date.now();
187
+ const isInvoking = shouldInvoke(time);
188
+
189
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
190
+ args[_key] = arguments[_key];
191
+ }
192
+
193
+ lastArgs = args;
194
+ lastThis = this;
195
+ lastCallTime = time;
196
+
197
+ if (isInvoking) {
198
+ if (!pending()) {
199
+ return leadingEdge(lastCallTime);
200
+ }
201
+
202
+ if (maxing) {
203
+ // Handle invocations in a tight loop.
204
+ startTimer(timerExpired, wait);
205
+ return invokeFunc(lastCallTime);
206
+ }
207
+ }
208
+
209
+ if (!pending()) {
210
+ startTimer(timerExpired, wait);
211
+ }
212
+
213
+ return result;
214
+ }
215
+
216
+ debounced.cancel = cancel;
217
+ debounced.flush = flush;
218
+ debounced.pending = pending;
219
+ return debounced;
220
+ };
221
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/compose/src/utils/debounce/index.ts"],"names":["debounce","func","wait","options","lastArgs","lastThis","maxWait","result","timerId","lastCallTime","lastInvokeTime","leading","maxing","trailing","undefined","Math","max","invokeFunc","time","args","thisArg","apply","startTimer","pendingFunc","waitTime","setTimeout","cancelTimer","clearTimeout","leadingEdge","timerExpired","getTimeSinceLastCall","remainingWait","timeSinceLastCall","timeSinceLastInvoke","timeWaiting","min","shouldInvoke","Date","now","trailingEdge","clearTimer","cancel","flush","pending","debounced","isInvoking"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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gB3B,IAAhB,CAAV;AACA,eAAOe,UAAU,CAAER,YAAF,CAAjB;AACA;AACD;;AACD,QAAK,CAAEkC,OAAO,EAAd,EAAmB;AAClBrB,MAAAA,UAAU,CAAEO,YAAF,EAAgB3B,IAAhB,CAAV;AACA;;AACD,WAAOK,MAAP;AACA;;AACDqC,EAAAA,SAAS,CAACH,MAAV,GAAmBA,MAAnB;AACAG,EAAAA,SAAS,CAACF,KAAV,GAAkBA,KAAlB;AACAE,EAAAA,SAAS,CAACD,OAAV,GAAoBA,OAApB;AACA,SAAOC,SAAP;AACA,CA7JM","sourcesContent":["/**\n * Parts of this source were derived and modified from lodash,\n * released under the MIT license.\n *\n * https://github.com/lodash/lodash\n *\n * Copyright JS Foundation and other contributors <https://js.foundation/>\n *\n * Based on Underscore.js, copyright Jeremy Ashkenas,\n * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>\n *\n * This software consists of voluntary contributions made by many\n * individuals. For exact contribution history, see the revision history\n * available at https://github.com/lodash/lodash\n *\n * The following license applies to all parts of this software except as\n * documented below:\n *\n * ====\n *\n * Permission is hereby granted, free of charge, to any person obtaining\n * a copy of this software and associated documentation files (the\n * \"Software\"), to deal in the Software without restriction, including\n * without limitation the rights to use, copy, modify, merge, publish,\n * distribute, sublicense, and/or sell copies of the Software, and to\n * permit persons to whom the Software is furnished to do so, subject to\n * the following conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\nexport interface DebounceOptions {\n\tleading: boolean;\n\tmaxWait: number;\n\ttrailing: boolean;\n}\n\nexport interface DebouncedFunc< T extends ( ...args: any[] ) => any > {\n\t/**\n\t * Call the original function, but applying the debounce rules.\n\t *\n\t * If the debounced function can be run immediately, this calls it and returns its return\n\t * value.\n\t *\n\t * Otherwise, it returns the return value of the last invocation, or undefined if the debounced\n\t * function was not invoked yet.\n\t */\n\t( ...args: Parameters< T > ): ReturnType< T > | undefined;\n\n\t/**\n\t * Throw away any pending invocation of the debounced function.\n\t */\n\tcancel(): void;\n\n\t/**\n\t * If there is a pending invocation of the debounced function, invoke it immediately and return\n\t * its return value.\n\t *\n\t * Otherwise, return the value from the last invocation, or undefined if the debounced function\n\t * was never invoked.\n\t */\n\tflush(): ReturnType< T > | undefined;\n}\n\n/**\n * A simplified and properly typed version of lodash's `debounce`, that\n * always uses timers instead of sometimes using rAF.\n *\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked. The debounced function comes with a `cancel` method to cancel delayed\n * `func` invocations and a `flush` method to immediately invoke them. Provide\n * `options` to indicate whether `func` should be invoked on the leading and/or\n * trailing edge of the `wait` timeout. The `func` is invoked with the last\n * arguments provided to the debounced function. Subsequent calls to the debounced\n * function return the result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * @param {Function} func The function to debounce.\n * @param {number} wait The number of milliseconds to delay.\n * @param {Partial< DebounceOptions >} options The options object.\n * @param {boolean} options.leading Specify invoking on the leading edge of the timeout.\n * @param {number} options.maxWait The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.\n *\n * @return Returns the new debounced function.\n */\nexport const debounce = < FunctionT extends ( ...args: unknown[] ) => unknown >(\n\tfunc: FunctionT,\n\twait: number,\n\toptions?: Partial< DebounceOptions >\n) => {\n\tlet lastArgs: Parameters< FunctionT > | undefined;\n\tlet lastThis: unknown | undefined;\n\tlet maxWait = 0;\n\tlet result: ReturnType< FunctionT >;\n\tlet timerId: ReturnType< typeof setTimeout > | undefined;\n\tlet lastCallTime: number | undefined;\n\n\tlet lastInvokeTime = 0;\n\tlet leading = false;\n\tlet maxing = false;\n\tlet trailing = true;\n\n\tif ( options ) {\n\t\tleading = !! options.leading;\n\t\tmaxing = 'maxWait' in options;\n\t\tif ( options.maxWait !== undefined ) {\n\t\t\tmaxWait = Math.max( options.maxWait, wait );\n\t\t}\n\t\ttrailing = 'trailing' in options ? !! options.trailing : trailing;\n\t}\n\n\tfunction invokeFunc( time: number ) {\n\t\tconst args = lastArgs;\n\t\tconst thisArg = lastThis;\n\n\t\tlastArgs = undefined;\n\t\tlastThis = undefined;\n\t\tlastInvokeTime = time;\n\n\t\tresult = func.apply( thisArg, args! ) as ReturnType< FunctionT >;\n\t\treturn result;\n\t}\n\n\tfunction startTimer(\n\t\tpendingFunc: () => void,\n\t\twaitTime: number | undefined\n\t) {\n\t\ttimerId = setTimeout( pendingFunc, waitTime );\n\t}\n\n\tfunction cancelTimer() {\n\t\tif ( timerId !== undefined ) {\n\t\t\tclearTimeout( timerId );\n\t\t}\n\t}\n\n\tfunction leadingEdge( time: number ) {\n\t\t// Reset any `maxWait` timer.\n\t\tlastInvokeTime = time;\n\t\t// Start the timer for the trailing edge.\n\t\tstartTimer( timerExpired, wait );\n\t\t// Invoke the leading edge.\n\t\treturn leading ? invokeFunc( time ) : result;\n\t}\n\n\tfunction getTimeSinceLastCall( time: number ) {\n\t\treturn time - ( lastCallTime || 0 );\n\t}\n\n\tfunction remainingWait( time: number ) {\n\t\tconst timeSinceLastCall = getTimeSinceLastCall( time );\n\t\tconst timeSinceLastInvoke = time - lastInvokeTime;\n\t\tconst timeWaiting = wait - timeSinceLastCall;\n\n\t\treturn maxing\n\t\t\t? Math.min( timeWaiting, maxWait - timeSinceLastInvoke )\n\t\t\t: timeWaiting;\n\t}\n\n\tfunction shouldInvoke( time: number ) {\n\t\tconst timeSinceLastCall = getTimeSinceLastCall( time );\n\t\tconst timeSinceLastInvoke = time - lastInvokeTime;\n\n\t\t// Either this is the first call, activity has stopped and we're at the\n\t\t// trailing edge, the system time has gone backwards and we're treating\n\t\t// it as the trailing edge, or we've hit the `maxWait` limit.\n\t\treturn (\n\t\t\tlastCallTime === undefined ||\n\t\t\ttimeSinceLastCall >= wait ||\n\t\t\ttimeSinceLastCall < 0 ||\n\t\t\t( maxing && timeSinceLastInvoke >= maxWait )\n\t\t);\n\t}\n\n\tfunction timerExpired() {\n\t\tconst time = Date.now();\n\t\tif ( shouldInvoke( time ) ) {\n\t\t\treturn trailingEdge( time );\n\t\t}\n\t\t// Restart the timer.\n\t\tstartTimer( timerExpired, remainingWait( time ) );\n\t\treturn undefined;\n\t}\n\n\tfunction clearTimer() {\n\t\ttimerId = undefined;\n\t}\n\n\tfunction trailingEdge( time: number ) {\n\t\tclearTimer();\n\n\t\t// Only invoke if we have `lastArgs` which means `func` has been\n\t\t// debounced at least once.\n\t\tif ( trailing && lastArgs ) {\n\t\t\treturn invokeFunc( time );\n\t\t}\n\t\tlastArgs = lastThis = undefined;\n\t\treturn result;\n\t}\n\n\tfunction cancel() {\n\t\tcancelTimer();\n\t\tlastInvokeTime = 0;\n\t\tclearTimer();\n\t\tlastArgs = lastCallTime = lastThis = undefined;\n\t}\n\n\tfunction flush() {\n\t\treturn pending() ? trailingEdge( Date.now() ) : result;\n\t}\n\n\tfunction pending() {\n\t\treturn timerId !== undefined;\n\t}\n\n\tfunction debounced( this: unknown, ...args: Parameters< FunctionT > ) {\n\t\tconst time = Date.now();\n\t\tconst isInvoking = shouldInvoke( time );\n\n\t\tlastArgs = args;\n\t\tlastThis = this;\n\t\tlastCallTime = time;\n\n\t\tif ( isInvoking ) {\n\t\t\tif ( ! pending() ) {\n\t\t\t\treturn leadingEdge( lastCallTime );\n\t\t\t}\n\t\t\tif ( maxing ) {\n\t\t\t\t// Handle invocations in a tight loop.\n\t\t\t\tstartTimer( timerExpired, wait );\n\t\t\t\treturn invokeFunc( lastCallTime );\n\t\t\t}\n\t\t}\n\t\tif ( ! pending() ) {\n\t\t\tstartTimer( timerExpired, wait );\n\t\t}\n\t\treturn result;\n\t}\n\tdebounced.cancel = cancel;\n\tdebounced.flush = flush;\n\tdebounced.pending = pending;\n\treturn debounced;\n};\n"]}
@@ -1,14 +1,11 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { flowRight as compose } from 'lodash';
5
1
  /**
6
2
  * Composes multiple higher-order components into a single higher-order component. Performs right-to-left function
7
3
  * composition, where each successive invocation is supplied the return value of the previous.
8
4
  *
9
- * This is just a re-export of `lodash`'s `flowRight` function.
5
+ * This is inspired by `lodash`'s `flowRight` function.
10
6
  *
11
7
  * @see https://docs-lodash.com/v4/flow-right/
12
8
  */
9
+ declare const compose: (...funcs: Function[]) => (...args: unknown[]) => unknown;
13
10
  export default compose;
14
11
  //# sourceMappingURL=compose.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/higher-order/compose.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,IAAI,OAAO,EAAE,MAAM,QAAQ,CAAC;AAE9C;;;;;;;GAOG;AACH,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/higher-order/compose.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,QAAA,MAAM,OAAO,2DAAmB,CAAC;AAEjC,eAAe,OAAO,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Parts of this source were derived and modified from lodash,
3
+ * released under the MIT license.
4
+ *
5
+ * https://github.com/lodash/lodash
6
+ *
7
+ * Copyright JS Foundation and other contributors <https://js.foundation/>
8
+ *
9
+ * Based on Underscore.js, copyright Jeremy Ashkenas,
10
+ * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
11
+ *
12
+ * This software consists of voluntary contributions made by many
13
+ * individuals. For exact contribution history, see the revision history
14
+ * available at https://github.com/lodash/lodash
15
+ *
16
+ * The following license applies to all parts of this software except as
17
+ * documented below:
18
+ *
19
+ * ====
20
+ *
21
+ * Permission is hereby granted, free of charge, to any person obtaining
22
+ * a copy of this software and associated documentation files (the
23
+ * "Software"), to deal in the Software without restriction, including
24
+ * without limitation the rights to use, copy, modify, merge, publish,
25
+ * distribute, sublicense, and/or sell copies of the Software, and to
26
+ * permit persons to whom the Software is furnished to do so, subject to
27
+ * the following conditions:
28
+ *
29
+ * The above copyright notice and this permission notice shall be
30
+ * included in all copies or substantial portions of the Software.
31
+ *
32
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
+ */
40
+ /**
41
+ * Creates a pipe function.
42
+ *
43
+ * Allows to choose whether to perform left-to-right or right-to-left composition.
44
+ *
45
+ * @see https://docs-lodash.com/v4/flow/
46
+ *
47
+ * @param {boolean} reverse True if right-to-left, false for left-to-right composition.
48
+ */
49
+ declare const basePipe: (reverse?: boolean) => (...funcs: Function[]) => (...args: unknown[]) => unknown;
50
+ /**
51
+ * Composes multiple higher-order components into a single higher-order component. Performs left-to-right function
52
+ * composition, where each successive invocation is supplied the return value of the previous.
53
+ *
54
+ * This is inspired by `lodash`'s `flow` function.
55
+ *
56
+ * @see https://docs-lodash.com/v4/flow/
57
+ */
58
+ declare const pipe: (...funcs: Function[]) => (...args: unknown[]) => unknown;
59
+ export { basePipe };
60
+ export default pipe;
61
+ //# sourceMappingURL=pipe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipe.d.ts","sourceRoot":"","sources":["../../src/higher-order/pipe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH;;;;;;;;GAQG;AACH,QAAA,MAAM,QAAQ,aACF,OAAO,gBACN,QAAQ,EAAE,eACX,OAAO,EAAE,YASnB,CAAC;AAEH;;;;;;;GAOG;AACH,QAAA,MAAM,IAAI,aApBG,QAAQ,EAAE,eACX,OAAO,EAAE,YAmBE,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,CAAC;AAEpB,eAAe,IAAI,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Debounces a function with Lodash's `debounce`. A new debounced function will
2
+ * Debounces a function similar to Lodash's `debounce`. A new debounced function will
3
3
  * be returned and any scheduled calls cancelled if any of the arguments change,
4
4
  * including the function to debounce, so please wrap functions created on
5
5
  * render in components in `useCallback`.
@@ -8,10 +8,10 @@
8
8
  *
9
9
  * @template {(...args: any[]) => void} TFunc
10
10
  *
11
- * @param {TFunc} fn The function to debounce.
12
- * @param {number} [wait] The number of milliseconds to delay.
13
- * @param {import('lodash').DebounceSettings} [options] The options object.
14
- * @return {import('lodash').DebouncedFunc<TFunc>} Debounced function.
11
+ * @param {TFunc} fn The function to debounce.
12
+ * @param {number} [wait] The number of milliseconds to delay.
13
+ * @param {import('../../utils/debounce').DebounceOptions} [options] The options object.
14
+ * @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Debounced function.
15
15
  */
16
- export default function useDebounce<TFunc extends (...args: any[]) => void>(fn: TFunc, wait?: number | undefined, options?: import("lodash").DebounceSettings | undefined): import("lodash").DebouncedFunc<TFunc>;
16
+ export default function useDebounce<TFunc extends (...args: any[]) => void>(fn: TFunc, wait?: number | undefined, options?: import("../../utils/debounce").DebounceOptions | undefined): import("../../utils/debounce").DebouncedFunc<TFunc>;
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-debounce/index.js"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;GAcG;AACH,4DAPwB,GAAG,EAAE,KAAK,IAAI,wIAerC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-debounce/index.js"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;GAcG;AACH,4DAPwB,GAAG,EAAE,KAAK,IAAI,mKAcrC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-disabled/index.js"],"names":[],"mappings":"AAkCA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH;IAjB4B,UAAU,GAA3B,OAAO;IACN,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAgKnD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-disabled/index.js"],"names":[],"mappings":"AAmCA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH;IAjB4B,UAAU,GAA3B,OAAO;IACN,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAgKnD"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-drop-zone/index.js"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;GAaG;AACH;IAV2C,UAAU;IACV,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,UAAU,QAAtC,SAAS,KAAK,IAAI;IACU,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,SAAS,QAArC,UAAU,KAAK,IAAI;IACS,MAAM,QAAlC,SAAS,KAAK,IAAI;IAErB,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAmMnD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-drop-zone/index.js"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;GAaG;AACH;IAV2C,UAAU;IACV,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,UAAU,QAAtC,SAAS,KAAK,IAAI;IACU,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,SAAS,QAArC,UAAU,KAAK,IAAI;IACS,MAAM,QAAlC,SAAS,KAAK,IAAI;IAErB,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAqMnD"}
@@ -1,10 +1,15 @@
1
1
  /**
2
- * Provides a unique instance ID.
2
+ * Specify the useInstanceId *function* signatures.
3
3
  *
4
- * @param {object} object Object reference to create an id for.
5
- * @param {string} [prefix] Prefix for the unique id.
6
- * @param {string | number} [preferredId=''] Default ID to use.
7
- * @return {string | number} The unique instance id.
4
+ * More accurately, useInstanceId distinguishes between three different
5
+ * signatures:
6
+ *
7
+ * 1. When only object is given, the returned value is a number
8
+ * 2. When object and prefix is given, the returned value is a string
9
+ * 3. When preferredId is given, the returned value is the type of preferredId
8
10
  */
9
- export default function useInstanceId(object: object, prefix?: string | undefined, preferredId?: string | number | undefined): string | number;
11
+ declare function useInstanceId(object: object): number;
12
+ declare function useInstanceId(object: object, prefix: string): string;
13
+ declare function useInstanceId<T extends string | number>(object: object, prefix: string, preferredId?: T): T;
14
+ export default useInstanceId;
10
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-instance-id/index.js"],"names":[],"mappings":"AAyBA;;;;;;;GAOG;AACH,8CALW,MAAM,2EAGL,MAAM,GAAG,MAAM,CAS1B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-instance-id/index.ts"],"names":[],"mappings":"AAmBA;;;;;;;;;GASG;AACH,iBAAS,aAAa,CAAE,MAAM,EAAE,MAAM,GAAI,MAAM,CAAC;AACjD,iBAAS,aAAa,CAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAI,MAAM,CAAC;AACjE,iBAAS,aAAa,CAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EAChD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,CAAC,GACb,CAAC,CAAC;AAuBL,eAAe,aAAa,CAAC"}
@@ -1,5 +1,7 @@
1
1
  export * from "./utils/create-higher-order-component";
2
+ export * from "./utils/debounce";
2
3
  export { default as compose } from "./higher-order/compose";
4
+ export { default as pipe } from "./higher-order/pipe";
3
5
  export { default as ifCondition } from "./higher-order/if-condition";
4
6
  export { default as pure } from "./higher-order/pure";
5
7
  export { default as withGlobalEvents } from "./higher-order/with-global-events";
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Parts of this source were derived and modified from lodash,
3
+ * released under the MIT license.
4
+ *
5
+ * https://github.com/lodash/lodash
6
+ *
7
+ * Copyright JS Foundation and other contributors <https://js.foundation/>
8
+ *
9
+ * Based on Underscore.js, copyright Jeremy Ashkenas,
10
+ * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
11
+ *
12
+ * This software consists of voluntary contributions made by many
13
+ * individuals. For exact contribution history, see the revision history
14
+ * available at https://github.com/lodash/lodash
15
+ *
16
+ * The following license applies to all parts of this software except as
17
+ * documented below:
18
+ *
19
+ * ====
20
+ *
21
+ * Permission is hereby granted, free of charge, to any person obtaining
22
+ * a copy of this software and associated documentation files (the
23
+ * "Software"), to deal in the Software without restriction, including
24
+ * without limitation the rights to use, copy, modify, merge, publish,
25
+ * distribute, sublicense, and/or sell copies of the Software, and to
26
+ * permit persons to whom the Software is furnished to do so, subject to
27
+ * the following conditions:
28
+ *
29
+ * The above copyright notice and this permission notice shall be
30
+ * included in all copies or substantial portions of the Software.
31
+ *
32
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
+ */
40
+ export interface DebounceOptions {
41
+ leading: boolean;
42
+ maxWait: number;
43
+ trailing: boolean;
44
+ }
45
+ export interface DebouncedFunc<T extends (...args: any[]) => any> {
46
+ /**
47
+ * Call the original function, but applying the debounce rules.
48
+ *
49
+ * If the debounced function can be run immediately, this calls it and returns its return
50
+ * value.
51
+ *
52
+ * Otherwise, it returns the return value of the last invocation, or undefined if the debounced
53
+ * function was not invoked yet.
54
+ */
55
+ (...args: Parameters<T>): ReturnType<T> | undefined;
56
+ /**
57
+ * Throw away any pending invocation of the debounced function.
58
+ */
59
+ cancel(): void;
60
+ /**
61
+ * If there is a pending invocation of the debounced function, invoke it immediately and return
62
+ * its return value.
63
+ *
64
+ * Otherwise, return the value from the last invocation, or undefined if the debounced function
65
+ * was never invoked.
66
+ */
67
+ flush(): ReturnType<T> | undefined;
68
+ }
69
+ /**
70
+ * A simplified and properly typed version of lodash's `debounce`, that
71
+ * always uses timers instead of sometimes using rAF.
72
+ *
73
+ * Creates a debounced function that delays invoking `func` until after `wait`
74
+ * milliseconds have elapsed since the last time the debounced function was
75
+ * invoked. The debounced function comes with a `cancel` method to cancel delayed
76
+ * `func` invocations and a `flush` method to immediately invoke them. Provide
77
+ * `options` to indicate whether `func` should be invoked on the leading and/or
78
+ * trailing edge of the `wait` timeout. The `func` is invoked with the last
79
+ * arguments provided to the debounced function. Subsequent calls to the debounced
80
+ * function return the result of the last `func` invocation.
81
+ *
82
+ * **Note:** If `leading` and `trailing` options are `true`, `func` is
83
+ * invoked on the trailing edge of the timeout only if the debounced function
84
+ * is invoked more than once during the `wait` timeout.
85
+ *
86
+ * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
87
+ * until the next tick, similar to `setTimeout` with a timeout of `0`.
88
+ *
89
+ * @param {Function} func The function to debounce.
90
+ * @param {number} wait The number of milliseconds to delay.
91
+ * @param {Partial< DebounceOptions >} options The options object.
92
+ * @param {boolean} options.leading Specify invoking on the leading edge of the timeout.
93
+ * @param {number} options.maxWait The maximum time `func` is allowed to be delayed before it's invoked.
94
+ * @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.
95
+ *
96
+ * @return Returns the new debounced function.
97
+ */
98
+ export declare const debounce: <FunctionT extends (...args: unknown[]) => unknown>(func: FunctionT, wait: number, options?: Partial<DebounceOptions> | undefined) => {
99
+ (this: unknown, ...args: Parameters<FunctionT>): ReturnType<FunctionT>;
100
+ cancel: () => void;
101
+ flush: () => ReturnType<FunctionT>;
102
+ pending: () => boolean;
103
+ };
104
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/debounce/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,MAAM,WAAW,eAAe;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,aAAa,CAAE,CAAC,SAAS,CAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAM,GAAG;IAClE;;;;;;;;OAQG;IACH,CAAE,GAAG,IAAI,EAAE,UAAU,CAAE,CAAC,CAAE,GAAI,UAAU,CAAE,CAAC,CAAE,GAAG,SAAS,CAAC;IAE1D;;OAEG;IACH,MAAM,IAAI,IAAI,CAAC;IAEf;;;;;;OAMG;IACH,KAAK,IAAI,UAAU,CAAE,CAAC,CAAE,GAAG,SAAS,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,QAAQ,+BAAkC,OAAO,EAAE,KAAM,OAAO,yBAEtE,MAAM;WAgIc,OAAO;;;;CA2BjC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/compose",
3
- "version": "5.15.2",
3
+ "version": "5.16.0",
4
4
  "description": "WordPress higher-order components (HOCs).",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -32,12 +32,12 @@
32
32
  "@babel/runtime": "^7.16.0",
33
33
  "@types/lodash": "^4.14.172",
34
34
  "@types/mousetrap": "^1.6.8",
35
- "@wordpress/deprecated": "^3.17.1",
36
- "@wordpress/dom": "^3.17.2",
37
- "@wordpress/element": "^4.15.1",
38
- "@wordpress/is-shallow-equal": "^4.17.1",
39
- "@wordpress/keycodes": "^3.17.1",
40
- "@wordpress/priority-queue": "^2.17.2",
35
+ "@wordpress/deprecated": "^3.18.0",
36
+ "@wordpress/dom": "^3.18.0",
37
+ "@wordpress/element": "^4.16.0",
38
+ "@wordpress/is-shallow-equal": "^4.18.0",
39
+ "@wordpress/keycodes": "^3.18.0",
40
+ "@wordpress/priority-queue": "^2.18.0",
41
41
  "change-case": "^4.1.2",
42
42
  "clipboard": "^2.0.8",
43
43
  "lodash": "^4.17.21",
@@ -50,5 +50,5 @@
50
50
  "publishConfig": {
51
51
  "access": "public"
52
52
  },
53
- "gitHead": "f6021282457317c7e12dcc3a3f02c9ac28e16a30"
53
+ "gitHead": "23e136283fa1d3b8d9d8b33869f871ad5eb77726"
54
54
  }
@@ -1,14 +1,16 @@
1
1
  /**
2
- * External dependencies
2
+ * Internal dependencies
3
3
  */
4
- import { flowRight as compose } from 'lodash';
4
+ import { basePipe } from './pipe';
5
5
 
6
6
  /**
7
7
  * Composes multiple higher-order components into a single higher-order component. Performs right-to-left function
8
8
  * composition, where each successive invocation is supplied the return value of the previous.
9
9
  *
10
- * This is just a re-export of `lodash`'s `flowRight` function.
10
+ * This is inspired by `lodash`'s `flowRight` function.
11
11
  *
12
12
  * @see https://docs-lodash.com/v4/flow-right/
13
13
  */
14
+ const compose = basePipe( true );
15
+
14
16
  export default compose;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Parts of this source were derived and modified from lodash,
3
+ * released under the MIT license.
4
+ *
5
+ * https://github.com/lodash/lodash
6
+ *
7
+ * Copyright JS Foundation and other contributors <https://js.foundation/>
8
+ *
9
+ * Based on Underscore.js, copyright Jeremy Ashkenas,
10
+ * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
11
+ *
12
+ * This software consists of voluntary contributions made by many
13
+ * individuals. For exact contribution history, see the revision history
14
+ * available at https://github.com/lodash/lodash
15
+ *
16
+ * The following license applies to all parts of this software except as
17
+ * documented below:
18
+ *
19
+ * ====
20
+ *
21
+ * Permission is hereby granted, free of charge, to any person obtaining
22
+ * a copy of this software and associated documentation files (the
23
+ * "Software"), to deal in the Software without restriction, including
24
+ * without limitation the rights to use, copy, modify, merge, publish,
25
+ * distribute, sublicense, and/or sell copies of the Software, and to
26
+ * permit persons to whom the Software is furnished to do so, subject to
27
+ * the following conditions:
28
+ *
29
+ * The above copyright notice and this permission notice shall be
30
+ * included in all copies or substantial portions of the Software.
31
+ *
32
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
+ */
40
+
41
+ /**
42
+ * Creates a pipe function.
43
+ *
44
+ * Allows to choose whether to perform left-to-right or right-to-left composition.
45
+ *
46
+ * @see https://docs-lodash.com/v4/flow/
47
+ *
48
+ * @param {boolean} reverse True if right-to-left, false for left-to-right composition.
49
+ */
50
+ const basePipe =
51
+ ( reverse: boolean = false ) =>
52
+ ( ...funcs: Function[] ) =>
53
+ ( ...args: unknown[] ) => {
54
+ const functions = funcs.flat();
55
+ if ( reverse ) {
56
+ functions.reverse();
57
+ }
58
+ return functions.reduce(
59
+ ( prev, func ) => [ func( ...prev ) ],
60
+ args
61
+ )[ 0 ];
62
+ };
63
+
64
+ /**
65
+ * Composes multiple higher-order components into a single higher-order component. Performs left-to-right function
66
+ * composition, where each successive invocation is supplied the return value of the previous.
67
+ *
68
+ * This is inspired by `lodash`'s `flow` function.
69
+ *
70
+ * @see https://docs-lodash.com/v4/flow/
71
+ */
72
+ const pipe = basePipe();
73
+
74
+ export { basePipe };
75
+
76
+ export default pipe;