@wordpress/compose 8.7.0 → 8.7.2-next.v.202609031004.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.
- package/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/build/higher-order/pipe.cjs.map +1 -1
- package/build/higher-order/with-global-events/index.cjs +1 -1
- package/build/higher-order/with-global-events/index.cjs.map +1 -1
- package/build/higher-order/with-state/index.cjs +1 -1
- package/build/higher-order/with-state/index.cjs.map +1 -1
- package/build-module/higher-order/pipe.mjs.map +1 -1
- package/build-module/higher-order/with-global-events/index.mjs +1 -1
- package/build-module/higher-order/with-global-events/index.mjs.map +1 -1
- package/build-module/higher-order/with-state/index.mjs +1 -1
- package/build-module/higher-order/with-state/index.mjs.map +1 -1
- package/build-types/higher-order/compose.d.ts +1 -1
- package/build-types/higher-order/compose.d.ts.map +1 -1
- package/build-types/higher-order/pipe.d.ts +2 -2
- package/build-types/higher-order/pipe.d.ts.map +1 -1
- package/build-types/higher-order/with-global-events/index.d.ts.map +1 -1
- package/build-types/higher-order/with-state/index.d.ts.map +1 -1
- package/package.json +12 -11
- package/src/higher-order/pipe.ts +1 -1
- package/src/higher-order/test/compose.ts +12 -11
- package/src/higher-order/test/pipe.ts +12 -11
- package/src/hooks/use-media-query/test/{ssr.js → ssr.jsx} +1 -3
- package/src/utils/create-higher-order-component/test/{index.js → index.jsx} +1 -0
- package/src/utils/debounce/test/index.ts +4 -3
- package/src/utils/observable-map/test/index.js +3 -2
- package/src/utils/throttle/test/index.ts +18 -17
- /package/src/higher-order/pure/test/{index.js → index.jsdom.test.jsx} +0 -0
- /package/src/higher-order/with-global-events/{index.js → index.jsx} +0 -0
- /package/src/higher-order/with-global-events/test/{index.js → index.jsdom.test.jsx} +0 -0
- /package/src/higher-order/with-global-events/test/{listener.js → listener.jsdom.test.js} +0 -0
- /package/src/higher-order/with-instance-id/test/{index.js → index.jsdom.test.jsx} +0 -0
- /package/src/higher-order/with-state/{index.js → index.jsx} +0 -0
- /package/src/higher-order/with-state/test/{index.js → index.jsdom.test.jsx} +0 -0
- /package/src/hooks/use-copy-on-click/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/hooks/use-copy-to-clipboard/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/hooks/use-dialog/test/{index.tsx → index.jsdom.test.tsx} +0 -0
- /package/src/hooks/use-disabled/test/{index.js → index.jsdom.test.jsx} +0 -0
- /package/src/hooks/use-drop-zone/test/{index.js → index.jsdom.test.jsx} +0 -0
- /package/src/hooks/use-focus-outside/test/{index.js → index.jsdom.test.jsx} +0 -0
- /package/src/hooks/use-instance-id/test/{index.js → index.jsdom.test.jsx} +0 -0
- /package/src/hooks/use-media-query/test/{index.js → index.jsdom.test.jsx} +0 -0
- /package/src/hooks/use-merge-refs/test/{index.js → index.jsdom.test.jsx} +0 -0
- /package/src/hooks/use-observable-value/test/{index.js → index.jsdom.test.jsx} +0 -0
- /package/src/hooks/use-state-with-history/test/{index.js → index.jsdom.test.jsx} +0 -0
- /package/src/hooks/use-viewport-match/test/{index.js → index.jsdom.test.jsx} +0 -0
- /package/src/utils/subscribe-delegated-listener/test/{index.js → index.jsdom.test.js} +0 -0
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ const compose = ( f, g ) => x
|
|
|
11
11
|
=> f( g( x ) );
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
Here's a simplified example of **compose** in use from Gutenberg's [`PluginSidebar` component](https://github.com/WordPress/gutenberg/blob/HEAD/packages/editor/src/components/plugin-sidebar/index.
|
|
14
|
+
Here's a simplified example of **compose** in use from Gutenberg's [`PluginSidebar` component](https://github.com/WordPress/gutenberg/blob/HEAD/packages/editor/src/components/plugin-sidebar/index.jsx):
|
|
15
15
|
|
|
16
16
|
Using compose:
|
|
17
17
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/higher-order/pipe.ts"],
|
|
4
|
-
"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\n/**\n * Creates a pipe function.\n *\n * Allows to choose whether to perform left-to-right or right-to-left composition.\n *\n * @see https://lodash.com/docs/4#flow\n *\n * @param {boolean} reverse True if right-to-left, false for left-to-right composition.\n */\nconst basePipe =\n\t( reverse: boolean = false ) =>\n\t( ...funcs: Function[] ) =>\n\t( ...args: unknown[] ) => {\n\t\tconst functions = funcs.flat();\n\t\tif ( reverse ) {\n\t\t\tfunctions.reverse();\n\t\t}\n\t\treturn functions.reduce(\n\t\t\t( prev, func ) => [ func( ...prev ) ],\n\t\t\targs\n\t\t)[ 0 ];\n\t};\n\n/**\n * Composes multiple higher-order components into a single higher-order component. Performs left-to-right function\n * composition, where each successive invocation is supplied the return value of the previous.\n *\n * This is inspired by `lodash`'s `flow` function.\n *\n * @see https://lodash.com/docs/4#flow\n */\nconst pipe = basePipe();\n\nexport { basePipe };\n\nexport default pipe;\n"],
|
|
4
|
+
"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\n/**\n * Creates a pipe function.\n *\n * Allows to choose whether to perform left-to-right or right-to-left composition.\n *\n * @see https://lodash.com/docs/4#flow\n *\n * @param {boolean} reverse True if right-to-left, false for left-to-right composition.\n */\nconst basePipe =\n\t( reverse: boolean = false ) =>\n\t( ...funcs: ( Function | Function[] )[] ) =>\n\t( ...args: unknown[] ) => {\n\t\tconst functions = funcs.flat();\n\t\tif ( reverse ) {\n\t\t\tfunctions.reverse();\n\t\t}\n\t\treturn functions.reduce(\n\t\t\t( prev, func ) => [ func( ...prev ) ],\n\t\t\targs\n\t\t)[ 0 ];\n\t};\n\n/**\n * Composes multiple higher-order components into a single higher-order component. Performs left-to-right function\n * composition, where each successive invocation is supplied the return value of the previous.\n *\n * This is inspired by `lodash`'s `flow` function.\n *\n * @see https://lodash.com/docs/4#flow\n */\nconst pipe = basePipe();\n\nexport { basePipe };\n\nexport default pipe;\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiDA,IAAM,WACL,CAAE,UAAmB,UACrB,IAAK,UACL,IAAK,SAAqB;AACzB,QAAM,YAAY,MAAM,KAAK;AAC7B,MAAK,SAAU;AACd,cAAU,QAAQ;AAAA,EACnB;AACA,SAAO,UAAU;AAAA,IAChB,CAAE,MAAM,SAAU,CAAE,KAAM,GAAG,IAAK,CAAE;AAAA,IACpC;AAAA,EACD,EAAG,CAAE;AACN;AAUD,IAAM,OAAO,SAAS;AAItB,IAAO,eAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// packages/compose/src/higher-order/with-global-events/index.
|
|
30
|
+
// packages/compose/src/higher-order/with-global-events/index.jsx
|
|
31
31
|
var with_global_events_exports = {};
|
|
32
32
|
__export(with_global_events_exports, {
|
|
33
33
|
default: () => withGlobalEvents
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/higher-order/with-global-events/index.
|
|
3
|
+
"sources": ["../../../src/higher-order/with-global-events/index.jsx"],
|
|
4
4
|
"sourcesContent": ["import { Component, forwardRef } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\nimport Listener from './listener';\n\n/**\n * Listener instance responsible for managing document event handling.\n */\nconst listener = new Listener();\n\n/**\n * Higher-order component creator which, given an object of DOM event types and\n * values corresponding to a callback function name on the component, will\n * create or update a window event handler to invoke the callback when an event\n * occurs. On behalf of the consuming developer, the higher-order component\n * manages unbinding when the component unmounts, and binding at most a single\n * event handler for the entire application.\n *\n * @deprecated\n *\n * @param {Record<keyof GlobalEventHandlersEventMap, string>} eventTypesToHandlers Object with keys of DOM\n * event type, the value a\n * name of the function on\n * the original component's\n * instance which handles\n * the event.\n *\n * @return {any} Higher-order component.\n */\nexport default function withGlobalEvents( eventTypesToHandlers ) {\n\tdeprecated( 'wp.compose.withGlobalEvents', {\n\t\tsince: '5.7',\n\t\talternative: 'useEffect',\n\t} );\n\n\treturn createHigherOrderComponent( ( WrappedComponent ) => {\n\t\tclass Wrapper extends Component {\n\t\t\tconstructor( /** @type {any} */ props ) {\n\t\t\t\tsuper( props );\n\n\t\t\t\tthis.handleEvent = this.handleEvent.bind( this );\n\t\t\t\tthis.handleRef = this.handleRef.bind( this );\n\t\t\t}\n\n\t\t\tcomponentDidMount() {\n\t\t\t\tObject.keys( eventTypesToHandlers ).forEach( ( eventType ) => {\n\t\t\t\t\tlistener.add( eventType, this );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tcomponentWillUnmount() {\n\t\t\t\tObject.keys( eventTypesToHandlers ).forEach( ( eventType ) => {\n\t\t\t\t\tlistener.remove( eventType, this );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\thandleEvent( /** @type {any} */ event ) {\n\t\t\t\tconst handler =\n\t\t\t\t\teventTypesToHandlers[\n\t\t\t\t\t\t/** @type {keyof GlobalEventHandlersEventMap} */ (\n\t\t\t\t\t\t\tevent.type\n\t\t\t\t\t\t)\n\t\t\t\t\t];\n\t\t\t\tif ( typeof this.wrappedRef[ handler ] === 'function' ) {\n\t\t\t\t\tthis.wrappedRef[ handler ]( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\thandleRef( /** @type {any} */ el ) {\n\t\t\t\tthis.wrappedRef = el;\n\t\t\t\t// Any component using `withGlobalEvents` that is not setting a `ref`\n\t\t\t\t// will cause `this.props.forwardedRef` to be `null`, so we need this\n\t\t\t\t// check.\n\t\t\t\tif ( this.props.forwardedRef ) {\n\t\t\t\t\tthis.props.forwardedRef( el );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn (\n\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t{ ...this.props.ownProps }\n\t\t\t\t\t\tref={ this.handleRef }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn forwardRef( ( props, ref ) => {\n\t\t\treturn <Wrapper ownProps={ props } forwardedRef={ ref } />;\n\t\t} );\n\t}, 'withGlobalEvents' );\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAsC;AACtC,wBAAuB;AACvB,2CAA2C;AAC3C,sBAAqB;AA6EhB;AAxEL,IAAM,WAAW,IAAI,gBAAAA,QAAS;AAqBf,SAAR,iBAAmC,sBAAuB;AAChE,wBAAAC,SAAY,+BAA+B;AAAA,IAC1C,OAAO;AAAA,IACP,aAAa;AAAA,EACd,CAAE;AAEF,aAAO,iEAA4B,CAAE,qBAAsB;AAAA,IAC1D,MAAM,gBAAgB,yBAAU;AAAA,MAC/B,YAAgC,OAAQ;AACvC,cAAO,KAAM;AAEb,aAAK,cAAc,KAAK,YAAY,KAAM,IAAK;AAC/C,aAAK,YAAY,KAAK,UAAU,KAAM,IAAK;AAAA,MAC5C;AAAA,MAEA,oBAAoB;AACnB,eAAO,KAAM,oBAAqB,EAAE,QAAS,CAAE,cAAe;AAC7D,mBAAS,IAAK,WAAW,IAAK;AAAA,QAC/B,CAAE;AAAA,MACH;AAAA,MAEA,uBAAuB;AACtB,eAAO,KAAM,oBAAqB,EAAE,QAAS,CAAE,cAAe;AAC7D,mBAAS,OAAQ,WAAW,IAAK;AAAA,QAClC,CAAE;AAAA,MACH;AAAA,MAEA,YAAgC,OAAQ;AACvC,cAAM,UACL;AAAA;AAAA,UAEE,MAAM;AAAA,QAER;AACD,YAAK,OAAO,KAAK,WAAY,OAAQ,MAAM,YAAa;AACvD,eAAK,WAAY,OAAQ,EAAG,KAAM;AAAA,QACnC;AAAA,MACD;AAAA,MAEA,UAA8B,IAAK;AAClC,aAAK,aAAa;AAIlB,YAAK,KAAK,MAAM,cAAe;AAC9B,eAAK,MAAM,aAAc,EAAG;AAAA,QAC7B;AAAA,MACD;AAAA,MAEA,SAAS;AACR,eACC;AAAA,UAAC;AAAA;AAAA,YACE,GAAG,KAAK,MAAM;AAAA,YAChB,KAAM,KAAK;AAAA;AAAA,QACZ;AAAA,MAEF;AAAA,IACD;AAEA,eAAO,2BAAY,CAAE,OAAO,QAAS;AACpC,aAAO,4CAAC,WAAQ,UAAW,OAAQ,cAAe,KAAM;AAAA,IACzD,CAAE;AAAA,EACH,GAAG,kBAAmB;AACvB;",
|
|
6
6
|
"names": ["Listener", "deprecated"]
|
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// packages/compose/src/higher-order/with-state/index.
|
|
30
|
+
// packages/compose/src/higher-order/with-state/index.jsx
|
|
31
31
|
var with_state_exports = {};
|
|
32
32
|
__export(with_state_exports, {
|
|
33
33
|
default: () => withState
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/higher-order/with-state/index.
|
|
3
|
+
"sources": ["../../../src/higher-order/with-state/index.jsx"],
|
|
4
4
|
"sourcesContent": ["import { Component } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\n\n/**\n * A Higher Order Component used to provide and manage internal component state\n * via props.\n *\n * @deprecated Use `useState` instead.\n *\n * @param {any} initialState Optional initial state of the component.\n *\n * @return {any} A higher order component wrapper accepting a component that takes the state props + its own props + `setState` and returning a component that only accepts the own props.\n */\nexport default function withState( initialState = {} ) {\n\tdeprecated( 'wp.compose.withState', {\n\t\tsince: '5.8',\n\t\talternative: 'wp.element.useState',\n\t} );\n\n\treturn createHigherOrderComponent( ( OriginalComponent ) => {\n\t\treturn class WrappedComponent extends Component {\n\t\t\tconstructor( /** @type {any} */ props ) {\n\t\t\t\tsuper( props );\n\n\t\t\t\tthis.setState = this.setState.bind( this );\n\n\t\t\t\tthis.state = initialState;\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn (\n\t\t\t\t\t<OriginalComponent\n\t\t\t\t\t\t{ ...this.props }\n\t\t\t\t\t\t{ ...this.state }\n\t\t\t\t\t\tsetState={ this.setState }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t}, 'withState' );\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA0B;AAC1B,wBAAuB;AACvB,2CAA2C;AA8BtC;AAlBU,SAAR,UAA4B,eAAe,CAAC,GAAI;AACtD,wBAAAA,SAAY,wBAAwB;AAAA,IACnC,OAAO;AAAA,IACP,aAAa;AAAA,EACd,CAAE;AAEF,aAAO,iEAA4B,CAAE,sBAAuB;AAC3D,WAAO,MAAM,yBAAyB,yBAAU;AAAA,MAC/C,YAAgC,OAAQ;AACvC,cAAO,KAAM;AAEb,aAAK,WAAW,KAAK,SAAS,KAAM,IAAK;AAEzC,aAAK,QAAQ;AAAA,MACd;AAAA,MAEA,SAAS;AACR,eACC;AAAA,UAAC;AAAA;AAAA,YACE,GAAG,KAAK;AAAA,YACR,GAAG,KAAK;AAAA,YACV,UAAW,KAAK;AAAA;AAAA,QACjB;AAAA,MAEF;AAAA,IACD;AAAA,EACD,GAAG,WAAY;AAChB;",
|
|
6
6
|
"names": ["deprecated"]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/higher-order/pipe.ts"],
|
|
4
|
-
"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\n/**\n * Creates a pipe function.\n *\n * Allows to choose whether to perform left-to-right or right-to-left composition.\n *\n * @see https://lodash.com/docs/4#flow\n *\n * @param {boolean} reverse True if right-to-left, false for left-to-right composition.\n */\nconst basePipe =\n\t( reverse: boolean = false ) =>\n\t( ...funcs: Function[] ) =>\n\t( ...args: unknown[] ) => {\n\t\tconst functions = funcs.flat();\n\t\tif ( reverse ) {\n\t\t\tfunctions.reverse();\n\t\t}\n\t\treturn functions.reduce(\n\t\t\t( prev, func ) => [ func( ...prev ) ],\n\t\t\targs\n\t\t)[ 0 ];\n\t};\n\n/**\n * Composes multiple higher-order components into a single higher-order component. Performs left-to-right function\n * composition, where each successive invocation is supplied the return value of the previous.\n *\n * This is inspired by `lodash`'s `flow` function.\n *\n * @see https://lodash.com/docs/4#flow\n */\nconst pipe = basePipe();\n\nexport { basePipe };\n\nexport default pipe;\n"],
|
|
4
|
+
"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\n/**\n * Creates a pipe function.\n *\n * Allows to choose whether to perform left-to-right or right-to-left composition.\n *\n * @see https://lodash.com/docs/4#flow\n *\n * @param {boolean} reverse True if right-to-left, false for left-to-right composition.\n */\nconst basePipe =\n\t( reverse: boolean = false ) =>\n\t( ...funcs: ( Function | Function[] )[] ) =>\n\t( ...args: unknown[] ) => {\n\t\tconst functions = funcs.flat();\n\t\tif ( reverse ) {\n\t\t\tfunctions.reverse();\n\t\t}\n\t\treturn functions.reduce(\n\t\t\t( prev, func ) => [ func( ...prev ) ],\n\t\t\targs\n\t\t)[ 0 ];\n\t};\n\n/**\n * Composes multiple higher-order components into a single higher-order component. Performs left-to-right function\n * composition, where each successive invocation is supplied the return value of the previous.\n *\n * This is inspired by `lodash`'s `flow` function.\n *\n * @see https://lodash.com/docs/4#flow\n */\nconst pipe = basePipe();\n\nexport { basePipe };\n\nexport default pipe;\n"],
|
|
5
5
|
"mappings": ";AAiDA,IAAM,WACL,CAAE,UAAmB,UACrB,IAAK,UACL,IAAK,SAAqB;AACzB,QAAM,YAAY,MAAM,KAAK;AAC7B,MAAK,SAAU;AACd,cAAU,QAAQ;AAAA,EACnB;AACA,SAAO,UAAU;AAAA,IAChB,CAAE,MAAM,SAAU,CAAE,KAAM,GAAG,IAAK,CAAE;AAAA,IACpC;AAAA,EACD,EAAG,CAAE;AACN;AAUD,IAAM,OAAO,SAAS;AAItB,IAAO,eAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/compose/src/higher-order/with-global-events/index.
|
|
1
|
+
// packages/compose/src/higher-order/with-global-events/index.jsx
|
|
2
2
|
import { Component, forwardRef } from "@wordpress/element";
|
|
3
3
|
import deprecated from "@wordpress/deprecated";
|
|
4
4
|
import { createHigherOrderComponent } from "../../utils/create-higher-order-component/index.mjs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/higher-order/with-global-events/index.
|
|
3
|
+
"sources": ["../../../src/higher-order/with-global-events/index.jsx"],
|
|
4
4
|
"sourcesContent": ["import { Component, forwardRef } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\nimport Listener from './listener';\n\n/**\n * Listener instance responsible for managing document event handling.\n */\nconst listener = new Listener();\n\n/**\n * Higher-order component creator which, given an object of DOM event types and\n * values corresponding to a callback function name on the component, will\n * create or update a window event handler to invoke the callback when an event\n * occurs. On behalf of the consuming developer, the higher-order component\n * manages unbinding when the component unmounts, and binding at most a single\n * event handler for the entire application.\n *\n * @deprecated\n *\n * @param {Record<keyof GlobalEventHandlersEventMap, string>} eventTypesToHandlers Object with keys of DOM\n * event type, the value a\n * name of the function on\n * the original component's\n * instance which handles\n * the event.\n *\n * @return {any} Higher-order component.\n */\nexport default function withGlobalEvents( eventTypesToHandlers ) {\n\tdeprecated( 'wp.compose.withGlobalEvents', {\n\t\tsince: '5.7',\n\t\talternative: 'useEffect',\n\t} );\n\n\treturn createHigherOrderComponent( ( WrappedComponent ) => {\n\t\tclass Wrapper extends Component {\n\t\t\tconstructor( /** @type {any} */ props ) {\n\t\t\t\tsuper( props );\n\n\t\t\t\tthis.handleEvent = this.handleEvent.bind( this );\n\t\t\t\tthis.handleRef = this.handleRef.bind( this );\n\t\t\t}\n\n\t\t\tcomponentDidMount() {\n\t\t\t\tObject.keys( eventTypesToHandlers ).forEach( ( eventType ) => {\n\t\t\t\t\tlistener.add( eventType, this );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tcomponentWillUnmount() {\n\t\t\t\tObject.keys( eventTypesToHandlers ).forEach( ( eventType ) => {\n\t\t\t\t\tlistener.remove( eventType, this );\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\thandleEvent( /** @type {any} */ event ) {\n\t\t\t\tconst handler =\n\t\t\t\t\teventTypesToHandlers[\n\t\t\t\t\t\t/** @type {keyof GlobalEventHandlersEventMap} */ (\n\t\t\t\t\t\t\tevent.type\n\t\t\t\t\t\t)\n\t\t\t\t\t];\n\t\t\t\tif ( typeof this.wrappedRef[ handler ] === 'function' ) {\n\t\t\t\t\tthis.wrappedRef[ handler ]( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\thandleRef( /** @type {any} */ el ) {\n\t\t\t\tthis.wrappedRef = el;\n\t\t\t\t// Any component using `withGlobalEvents` that is not setting a `ref`\n\t\t\t\t// will cause `this.props.forwardedRef` to be `null`, so we need this\n\t\t\t\t// check.\n\t\t\t\tif ( this.props.forwardedRef ) {\n\t\t\t\t\tthis.props.forwardedRef( el );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn (\n\t\t\t\t\t<WrappedComponent\n\t\t\t\t\t\t{ ...this.props.ownProps }\n\t\t\t\t\t\tref={ this.handleRef }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn forwardRef( ( props, ref ) => {\n\t\t\treturn <Wrapper ownProps={ props } forwardedRef={ ref } />;\n\t\t} );\n\t}, 'withGlobalEvents' );\n}\n"],
|
|
5
5
|
"mappings": ";AAAA,SAAS,WAAW,kBAAkB;AACtC,OAAO,gBAAgB;AACvB,SAAS,kCAAkC;AAC3C,OAAO,cAAc;AA6EhB;AAxEL,IAAM,WAAW,IAAI,SAAS;AAqBf,SAAR,iBAAmC,sBAAuB;AAChE,aAAY,+BAA+B;AAAA,IAC1C,OAAO;AAAA,IACP,aAAa;AAAA,EACd,CAAE;AAEF,SAAO,2BAA4B,CAAE,qBAAsB;AAAA,IAC1D,MAAM,gBAAgB,UAAU;AAAA,MAC/B,YAAgC,OAAQ;AACvC,cAAO,KAAM;AAEb,aAAK,cAAc,KAAK,YAAY,KAAM,IAAK;AAC/C,aAAK,YAAY,KAAK,UAAU,KAAM,IAAK;AAAA,MAC5C;AAAA,MAEA,oBAAoB;AACnB,eAAO,KAAM,oBAAqB,EAAE,QAAS,CAAE,cAAe;AAC7D,mBAAS,IAAK,WAAW,IAAK;AAAA,QAC/B,CAAE;AAAA,MACH;AAAA,MAEA,uBAAuB;AACtB,eAAO,KAAM,oBAAqB,EAAE,QAAS,CAAE,cAAe;AAC7D,mBAAS,OAAQ,WAAW,IAAK;AAAA,QAClC,CAAE;AAAA,MACH;AAAA,MAEA,YAAgC,OAAQ;AACvC,cAAM,UACL;AAAA;AAAA,UAEE,MAAM;AAAA,QAER;AACD,YAAK,OAAO,KAAK,WAAY,OAAQ,MAAM,YAAa;AACvD,eAAK,WAAY,OAAQ,EAAG,KAAM;AAAA,QACnC;AAAA,MACD;AAAA,MAEA,UAA8B,IAAK;AAClC,aAAK,aAAa;AAIlB,YAAK,KAAK,MAAM,cAAe;AAC9B,eAAK,MAAM,aAAc,EAAG;AAAA,QAC7B;AAAA,MACD;AAAA,MAEA,SAAS;AACR,eACC;AAAA,UAAC;AAAA;AAAA,YACE,GAAG,KAAK,MAAM;AAAA,YAChB,KAAM,KAAK;AAAA;AAAA,QACZ;AAAA,MAEF;AAAA,IACD;AAEA,WAAO,WAAY,CAAE,OAAO,QAAS;AACpC,aAAO,oBAAC,WAAQ,UAAW,OAAQ,cAAe,KAAM;AAAA,IACzD,CAAE;AAAA,EACH,GAAG,kBAAmB;AACvB;",
|
|
6
6
|
"names": []
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/compose/src/higher-order/with-state/index.
|
|
1
|
+
// packages/compose/src/higher-order/with-state/index.jsx
|
|
2
2
|
import { Component } from "@wordpress/element";
|
|
3
3
|
import deprecated from "@wordpress/deprecated";
|
|
4
4
|
import { createHigherOrderComponent } from "../../utils/create-higher-order-component/index.mjs";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/higher-order/with-state/index.
|
|
3
|
+
"sources": ["../../../src/higher-order/with-state/index.jsx"],
|
|
4
4
|
"sourcesContent": ["import { Component } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\n\n/**\n * A Higher Order Component used to provide and manage internal component state\n * via props.\n *\n * @deprecated Use `useState` instead.\n *\n * @param {any} initialState Optional initial state of the component.\n *\n * @return {any} A higher order component wrapper accepting a component that takes the state props + its own props + `setState` and returning a component that only accepts the own props.\n */\nexport default function withState( initialState = {} ) {\n\tdeprecated( 'wp.compose.withState', {\n\t\tsince: '5.8',\n\t\talternative: 'wp.element.useState',\n\t} );\n\n\treturn createHigherOrderComponent( ( OriginalComponent ) => {\n\t\treturn class WrappedComponent extends Component {\n\t\t\tconstructor( /** @type {any} */ props ) {\n\t\t\t\tsuper( props );\n\n\t\t\t\tthis.setState = this.setState.bind( this );\n\n\t\t\t\tthis.state = initialState;\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn (\n\t\t\t\t\t<OriginalComponent\n\t\t\t\t\t\t{ ...this.props }\n\t\t\t\t\t\t{ ...this.state }\n\t\t\t\t\t\tsetState={ this.setState }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t}, 'withState' );\n}\n"],
|
|
5
5
|
"mappings": ";AAAA,SAAS,iBAAiB;AAC1B,OAAO,gBAAgB;AACvB,SAAS,kCAAkC;AA8BtC;AAlBU,SAAR,UAA4B,eAAe,CAAC,GAAI;AACtD,aAAY,wBAAwB;AAAA,IACnC,OAAO;AAAA,IACP,aAAa;AAAA,EACd,CAAE;AAEF,SAAO,2BAA4B,CAAE,sBAAuB;AAC3D,WAAO,MAAM,yBAAyB,UAAU;AAAA,MAC/C,YAAgC,OAAQ;AACvC,cAAO,KAAM;AAEb,aAAK,WAAW,KAAK,SAAS,KAAM,IAAK;AAEzC,aAAK,QAAQ;AAAA,MACd;AAAA,MAEA,SAAS;AACR,eACC;AAAA,UAAC;AAAA;AAAA,YACE,GAAG,KAAK;AAAA,YACR,GAAG,KAAK;AAAA,YACV,UAAW,KAAK;AAAA;AAAA,QACjB;AAAA,MAEF;AAAA,IACD;AAAA,EACD,GAAG,WAAY;AAChB;",
|
|
6
6
|
"names": []
|
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @see https://lodash.com/docs/4#flow-right
|
|
8
8
|
*/
|
|
9
|
-
declare const compose: (...funcs: Function[]) => (...args: unknown[]) => unknown;
|
|
9
|
+
declare const compose: (...funcs: (Function | Function[])[]) => (...args: unknown[]) => unknown;
|
|
10
10
|
export default compose;
|
|
11
11
|
//# sourceMappingURL=compose.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/higher-order/compose.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,QAAA,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/higher-order/compose.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,QAAA,MAAM,OAAO,0EAAmB,CAAC;eAElB,OAAO"}
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
*
|
|
47
47
|
* @param {boolean} reverse True if right-to-left, false for left-to-right composition.
|
|
48
48
|
*/
|
|
49
|
-
declare const basePipe: (reverse?: boolean) => (...funcs: Function[]) => (...args: unknown[]) => unknown;
|
|
49
|
+
declare const basePipe: (reverse?: boolean) => (...funcs: (Function | Function[])[]) => (...args: unknown[]) => unknown;
|
|
50
50
|
/**
|
|
51
51
|
* Composes multiple higher-order components into a single higher-order component. Performs left-to-right function
|
|
52
52
|
* composition, where each successive invocation is supplied the return value of the previous.
|
|
@@ -55,7 +55,7 @@ declare const basePipe: (reverse?: boolean) => (...funcs: Function[]) => (...arg
|
|
|
55
55
|
*
|
|
56
56
|
* @see https://lodash.com/docs/4#flow
|
|
57
57
|
*/
|
|
58
|
-
declare const pipe: (...funcs: Function[]) => (...args: unknown[]) => unknown;
|
|
58
|
+
declare const pipe: (...funcs: (Function | Function[])[]) => (...args: unknown[]) => unknown;
|
|
59
59
|
export { basePipe };
|
|
60
60
|
export default pipe;
|
|
61
61
|
//# sourceMappingURL=pipe.d.ts.map
|
|
@@ -1 +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,
|
|
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,CAAE,QAAQ,GAAG,QAAQ,EAAE,CAAE,EAAE,eAC5B,OAAO,EAAE,YASnB,CAAC;AAEH;;;;;;;GAOG;AACH,QAAA,MAAM,IAAI,aApBG,CAAE,QAAQ,GAAG,QAAQ,EAAE,CAAE,EAAE,eAC5B,OAAO,EAAE,YAmBE,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,CAAC;eAEL,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-global-events/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-global-events/index.jsx"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAE,oBAAoB,EATnD,MAAM,CAAC,MAAM,2BAA2B,EAAE,MAAM,CASG,GAFlD,GAAG,CAiEd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-state/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-state/index.jsx"],"names":[],"mappings":"AAIA;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAE,YAAY,GAJpC,GAIyC,GAFxC,GAAG,CA6Bd"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/compose",
|
|
3
|
-
"version": "8.7.0",
|
|
3
|
+
"version": "8.7.2-next.v.202609031004.0",
|
|
4
4
|
"description": "WordPress higher-order components (HOCs).",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
"sideEffects": false,
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@types/mousetrap": "^1.6.8",
|
|
49
|
-
"@wordpress/deprecated": "^4.54.0",
|
|
50
|
-
"@wordpress/dom": "^4.54.0",
|
|
51
|
-
"@wordpress/element": "^8.6.0",
|
|
52
|
-
"@wordpress/is-shallow-equal": "^5.54.0",
|
|
53
|
-
"@wordpress/keycodes": "^4.54.0",
|
|
54
|
-
"@wordpress/priority-queue": "^3.54.0",
|
|
55
|
-
"@wordpress/private-apis": "^1.54.0",
|
|
56
|
-
"@wordpress/undo-manager": "^1.54.0",
|
|
49
|
+
"@wordpress/deprecated": "^4.54.1-next.v.202609031004.0",
|
|
50
|
+
"@wordpress/dom": "^4.54.1-next.v.202609031004.0",
|
|
51
|
+
"@wordpress/element": "^8.6.2-next.v.202609031004.0",
|
|
52
|
+
"@wordpress/is-shallow-equal": "^5.54.1-next.v.202609031004.0",
|
|
53
|
+
"@wordpress/keycodes": "^4.54.1-next.v.202609031004.0",
|
|
54
|
+
"@wordpress/priority-queue": "^3.54.1-next.v.202609031004.0",
|
|
55
|
+
"@wordpress/private-apis": "^1.54.2-next.v.202609031004.0",
|
|
56
|
+
"@wordpress/undo-manager": "^1.54.1-next.v.202609031004.0",
|
|
57
57
|
"change-case": "^4.1.2",
|
|
58
58
|
"mousetrap": "^1.6.5",
|
|
59
59
|
"use-memo-one": "^1.1.1"
|
|
@@ -64,7 +64,8 @@
|
|
|
64
64
|
"@testing-library/user-event": "^14.6.1",
|
|
65
65
|
"@types/jest": "^30.0.0",
|
|
66
66
|
"mock-match-media": "^0.4.2",
|
|
67
|
-
"react-dom": "^18.3.1"
|
|
67
|
+
"react-dom": "^18.3.1",
|
|
68
|
+
"vitest": "^4.1.10"
|
|
68
69
|
},
|
|
69
70
|
"peerDependencies": {
|
|
70
71
|
"@types/react": "^18 || ^19",
|
|
@@ -78,5 +79,5 @@
|
|
|
78
79
|
"publishConfig": {
|
|
79
80
|
"access": "public"
|
|
80
81
|
},
|
|
81
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "7275d6c6d93b542fca3cd98cdb9c7344ddd11e19"
|
|
82
83
|
}
|
package/src/higher-order/pipe.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
1
2
|
import compose from '../compose';
|
|
2
3
|
|
|
3
4
|
describe( 'compose', () => {
|
|
@@ -6,27 +7,27 @@ describe( 'compose', () => {
|
|
|
6
7
|
} );
|
|
7
8
|
|
|
8
9
|
it( 'executes functions right-to-left when passed as separate arguments', () => {
|
|
9
|
-
const a = ( value ) => ( value += 'a' );
|
|
10
|
-
const b = ( value ) => ( value += 'b' );
|
|
11
|
-
const c = ( value ) => ( value += 'c' );
|
|
10
|
+
const a = ( value: string ) => ( value += 'a' );
|
|
11
|
+
const b = ( value: string ) => ( value += 'b' );
|
|
12
|
+
const c = ( value: string ) => ( value += 'c' );
|
|
12
13
|
|
|
13
14
|
expect( compose( a, b, c )( 'test' ) ).toBe( 'testcba' );
|
|
14
15
|
} );
|
|
15
16
|
|
|
16
17
|
it( 'executes functions right-to-left when passed as a single array', () => {
|
|
17
|
-
const a = ( value ) => ( value += 'a' );
|
|
18
|
-
const b = ( value ) => ( value += 'b' );
|
|
19
|
-
const c = ( value ) => ( value += 'c' );
|
|
18
|
+
const a = ( value: string ) => ( value += 'a' );
|
|
19
|
+
const b = ( value: string ) => ( value += 'b' );
|
|
20
|
+
const c = ( value: string ) => ( value += 'c' );
|
|
20
21
|
|
|
21
22
|
expect( compose( [ a, b, c ] )( 'test' ) ).toBe( 'testcba' );
|
|
22
23
|
} );
|
|
23
24
|
|
|
24
25
|
it( 'executes functions right-to-left when passed as a mix of separate arguments and arrays', () => {
|
|
25
|
-
const a = ( value ) => ( value += 'a' );
|
|
26
|
-
const b = ( value ) => ( value += 'b' );
|
|
27
|
-
const c = ( value ) => ( value += 'c' );
|
|
28
|
-
const d = ( value ) => ( value += 'd' );
|
|
29
|
-
const e = ( value ) => ( value += 'e' );
|
|
26
|
+
const a = ( value: string ) => ( value += 'a' );
|
|
27
|
+
const b = ( value: string ) => ( value += 'b' );
|
|
28
|
+
const c = ( value: string ) => ( value += 'c' );
|
|
29
|
+
const d = ( value: string ) => ( value += 'd' );
|
|
30
|
+
const e = ( value: string ) => ( value += 'e' );
|
|
30
31
|
|
|
31
32
|
expect( compose( [ a, b ], c, [ d ], e )( 'test' ) ).toBe(
|
|
32
33
|
'testedcba'
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
1
2
|
import pipe from '../pipe';
|
|
2
3
|
|
|
3
4
|
describe( 'pipe', () => {
|
|
@@ -6,27 +7,27 @@ describe( 'pipe', () => {
|
|
|
6
7
|
} );
|
|
7
8
|
|
|
8
9
|
it( 'executes functions left-to-right when passed as separate arguments', () => {
|
|
9
|
-
const a = ( value ) => ( value += 'a' );
|
|
10
|
-
const b = ( value ) => ( value += 'b' );
|
|
11
|
-
const c = ( value ) => ( value += 'c' );
|
|
10
|
+
const a = ( value: string ) => ( value += 'a' );
|
|
11
|
+
const b = ( value: string ) => ( value += 'b' );
|
|
12
|
+
const c = ( value: string ) => ( value += 'c' );
|
|
12
13
|
|
|
13
14
|
expect( pipe( a, b, c )( 'test' ) ).toBe( 'testabc' );
|
|
14
15
|
} );
|
|
15
16
|
|
|
16
17
|
it( 'executes functions left-to-right when passed as a single array', () => {
|
|
17
|
-
const a = ( value ) => ( value += 'a' );
|
|
18
|
-
const b = ( value ) => ( value += 'b' );
|
|
19
|
-
const c = ( value ) => ( value += 'c' );
|
|
18
|
+
const a = ( value: string ) => ( value += 'a' );
|
|
19
|
+
const b = ( value: string ) => ( value += 'b' );
|
|
20
|
+
const c = ( value: string ) => ( value += 'c' );
|
|
20
21
|
|
|
21
22
|
expect( pipe( [ a, b, c ] )( 'test' ) ).toBe( 'testabc' );
|
|
22
23
|
} );
|
|
23
24
|
|
|
24
25
|
it( 'executes functions left-to-right when passed as a mix of separate arguments and arrays', () => {
|
|
25
|
-
const a = ( value ) => ( value += 'a' );
|
|
26
|
-
const b = ( value ) => ( value += 'b' );
|
|
27
|
-
const c = ( value ) => ( value += 'c' );
|
|
28
|
-
const d = ( value ) => ( value += 'd' );
|
|
29
|
-
const e = ( value ) => ( value += 'e' );
|
|
26
|
+
const a = ( value: string ) => ( value += 'a' );
|
|
27
|
+
const b = ( value: string ) => ( value += 'b' );
|
|
28
|
+
const c = ( value: string ) => ( value += 'c' );
|
|
29
|
+
const d = ( value: string ) => ( value += 'd' );
|
|
30
|
+
const e = ( value: string ) => ( value += 'e' );
|
|
30
31
|
|
|
31
32
|
expect( pipe( [ a, b ], c, [ d ], e )( 'test' ) ).toBe( 'testabcde' );
|
|
32
33
|
} );
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
1
2
|
import { debounce } from '../index';
|
|
2
3
|
|
|
3
|
-
const identity = ( value ) => value;
|
|
4
|
+
const identity = < T >( value: T ) => value;
|
|
4
5
|
|
|
5
6
|
describe( 'debounce', () => {
|
|
6
7
|
it( 'should debounce a function', () => {
|
|
@@ -326,12 +327,12 @@ describe( 'debounce', () => {
|
|
|
326
327
|
|
|
327
328
|
it( 'should invoke the trailing call with the correct arguments and `this` binding', () => {
|
|
328
329
|
return new Promise( ( done ) => {
|
|
329
|
-
let actual;
|
|
330
|
+
let actual: unknown[] | undefined;
|
|
330
331
|
let callCount = 0;
|
|
331
332
|
const object = {};
|
|
332
333
|
|
|
333
334
|
const debounced = debounce(
|
|
334
|
-
function ( ...args ) {
|
|
335
|
+
function ( this: object, ...args: unknown[] ) {
|
|
335
336
|
actual = [ this ];
|
|
336
337
|
Array.prototype.push.apply( actual, args );
|
|
337
338
|
return ++callCount !== 2;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { describe, expect, test, vi } from 'vitest';
|
|
1
2
|
import { observableMap } from '..';
|
|
2
3
|
|
|
3
4
|
describe( 'ObservableMap', () => {
|
|
4
5
|
test( 'should observe individual values', () => {
|
|
5
6
|
const map = observableMap();
|
|
6
7
|
|
|
7
|
-
const listenerA =
|
|
8
|
-
const listenerB =
|
|
8
|
+
const listenerA = vi.fn();
|
|
9
|
+
const listenerB = vi.fn();
|
|
9
10
|
|
|
10
11
|
const unsubA = map.subscribe( 'a', listenerA );
|
|
11
12
|
const unsubB = map.subscribe( 'b', listenerB );
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
1
2
|
import { throttle } from '../index';
|
|
2
3
|
|
|
3
|
-
const identity = ( value ) => value;
|
|
4
|
+
const identity = < T >( value: T ) => value;
|
|
4
5
|
|
|
5
6
|
describe( 'throttle', () => {
|
|
6
7
|
beforeEach( () => {
|
|
7
|
-
|
|
8
|
+
vi.useFakeTimers();
|
|
8
9
|
} );
|
|
9
10
|
|
|
10
11
|
afterEach( () => {
|
|
11
|
-
|
|
12
|
+
vi.useRealTimers();
|
|
12
13
|
} );
|
|
13
14
|
|
|
14
15
|
it( 'should throttle a function', () => {
|
|
@@ -24,7 +25,7 @@ describe( 'throttle', () => {
|
|
|
24
25
|
const lastCount = callCount;
|
|
25
26
|
expect( callCount ).toBeGreaterThan( 0 );
|
|
26
27
|
|
|
27
|
-
|
|
28
|
+
vi.advanceTimersByTime( 64 );
|
|
28
29
|
|
|
29
30
|
expect( callCount ).toBeGreaterThan( lastCount );
|
|
30
31
|
} );
|
|
@@ -35,7 +36,7 @@ describe( 'throttle', () => {
|
|
|
35
36
|
|
|
36
37
|
expect( results ).toStrictEqual( [ 'a', 'a' ] );
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
vi.advanceTimersByTime( 64 );
|
|
39
40
|
|
|
40
41
|
results = [ throttled( 'c' ), throttled( 'd' ) ];
|
|
41
42
|
expect( results[ 0 ] ).not.toBe( 'a' );
|
|
@@ -61,7 +62,7 @@ describe( 'throttle', () => {
|
|
|
61
62
|
throttled();
|
|
62
63
|
throttled();
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
vi.advanceTimersByTime( 64 );
|
|
65
66
|
|
|
66
67
|
expect( callCount ).toBe( 2 );
|
|
67
68
|
global.Date.now = globalDateNow;
|
|
@@ -76,7 +77,7 @@ describe( 'throttle', () => {
|
|
|
76
77
|
throttled();
|
|
77
78
|
expect( callCount ).toBe( 1 );
|
|
78
79
|
|
|
79
|
-
|
|
80
|
+
vi.advanceTimersByTime( 64 );
|
|
80
81
|
|
|
81
82
|
expect( callCount ).toBe( 1 );
|
|
82
83
|
} );
|
|
@@ -100,11 +101,11 @@ describe( 'throttle', () => {
|
|
|
100
101
|
const start = Date.now();
|
|
101
102
|
while ( Date.now() - start < limit ) {
|
|
102
103
|
throttled();
|
|
103
|
-
|
|
104
|
+
vi.advanceTimersByTime( 1 );
|
|
104
105
|
}
|
|
105
106
|
const actual = callCount;
|
|
106
107
|
|
|
107
|
-
|
|
108
|
+
vi.advanceTimersByTime( 1 );
|
|
108
109
|
|
|
109
110
|
expect( actual ).toBeGreaterThan( 1 );
|
|
110
111
|
}
|
|
@@ -124,16 +125,16 @@ describe( 'throttle', () => {
|
|
|
124
125
|
|
|
125
126
|
throttled();
|
|
126
127
|
|
|
127
|
-
|
|
128
|
+
vi.advanceTimersByTime( 192 );
|
|
128
129
|
|
|
129
130
|
expect( callCount ).toBe( 1 );
|
|
130
131
|
throttled();
|
|
131
132
|
|
|
132
|
-
|
|
133
|
+
vi.advanceTimersByTime( 64 );
|
|
133
134
|
|
|
134
135
|
expect( callCount ).toBe( 1 );
|
|
135
136
|
|
|
136
|
-
|
|
137
|
+
vi.advanceTimersByTime( 130 );
|
|
137
138
|
|
|
138
139
|
expect( callCount ).toBe( 2 );
|
|
139
140
|
} );
|
|
@@ -152,7 +153,7 @@ describe( 'throttle', () => {
|
|
|
152
153
|
throttled();
|
|
153
154
|
expect( callCount ).toBe( 1 );
|
|
154
155
|
|
|
155
|
-
|
|
156
|
+
vi.advanceTimersByTime( 128 );
|
|
156
157
|
|
|
157
158
|
expect( callCount ).toBe( 2 );
|
|
158
159
|
} );
|
|
@@ -193,7 +194,7 @@ describe( 'throttle', () => {
|
|
|
193
194
|
expect( withoutTrailing( 'a' ) ).toBe( 'a' );
|
|
194
195
|
expect( withoutTrailing( 'b' ) ).toBe( 'a' );
|
|
195
196
|
|
|
196
|
-
|
|
197
|
+
vi.advanceTimersByTime( 256 );
|
|
197
198
|
|
|
198
199
|
expect( withCount ).toBe( 2 );
|
|
199
200
|
expect( withoutCount ).toBe( 1 );
|
|
@@ -213,12 +214,12 @@ describe( 'throttle', () => {
|
|
|
213
214
|
throttled();
|
|
214
215
|
throttled();
|
|
215
216
|
|
|
216
|
-
|
|
217
|
+
vi.advanceTimersByTime( 96 );
|
|
217
218
|
|
|
218
219
|
throttled();
|
|
219
220
|
throttled();
|
|
220
221
|
|
|
221
|
-
|
|
222
|
+
vi.advanceTimersByTime( 96 );
|
|
222
223
|
|
|
223
224
|
expect( callCount ).toBeGreaterThan( 1 );
|
|
224
225
|
} );
|
|
@@ -245,7 +246,7 @@ describe( 'throttle', () => {
|
|
|
245
246
|
expect( results ).toStrictEqual( [ 'a', 'a', 'a' ] );
|
|
246
247
|
expect( callCount ).toBe( 1 );
|
|
247
248
|
|
|
248
|
-
|
|
249
|
+
vi.advanceTimersByTime( 64 );
|
|
249
250
|
|
|
250
251
|
expect( callCount ).toBe( 2 );
|
|
251
252
|
global.Date.now = globalDateNow;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|