@wordpress/data 9.9.0 → 9.10.1
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/build/components/async-mode-provider/context.js +2 -3
- package/build/components/async-mode-provider/context.js.map +1 -1
- package/build/components/async-mode-provider/index.js +0 -5
- package/build/components/async-mode-provider/index.js.map +1 -1
- package/build/components/async-mode-provider/use-async-mode.js +1 -3
- package/build/components/async-mode-provider/use-async-mode.js.map +1 -1
- package/build/components/registry-provider/context.js +3 -6
- package/build/components/registry-provider/context.js.map +1 -1
- package/build/components/registry-provider/index.js +0 -5
- package/build/components/registry-provider/index.js.map +1 -1
- package/build/components/registry-provider/use-registry.js +0 -3
- package/build/components/registry-provider/use-registry.js.map +1 -1
- package/build/components/use-dispatch/index.js +0 -3
- package/build/components/use-dispatch/index.js.map +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.js +0 -7
- package/build/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
- package/build/components/use-dispatch/use-dispatch.js +0 -5
- package/build/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build/components/use-select/index.js +35 -53
- package/build/components/use-select/index.js.map +1 -1
- package/build/components/with-dispatch/index.js +2 -7
- package/build/components/with-dispatch/index.js.map +1 -1
- package/build/components/with-registry/index.js +2 -5
- package/build/components/with-registry/index.js.map +1 -1
- package/build/components/with-select/index.js +2 -8
- package/build/components/with-select/index.js.map +1 -1
- package/build/controls.js +4 -10
- package/build/controls.js.map +1 -1
- package/build/default-registry.js +0 -3
- package/build/default-registry.js.map +1 -1
- package/build/dispatch.js +0 -3
- package/build/dispatch.js.map +1 -1
- package/build/factory.js +2 -5
- package/build/factory.js.map +1 -1
- package/build/index.js +7 -28
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +1 -2
- package/build/lock-unlock.js.map +1 -1
- package/build/plugins/index.js +0 -2
- package/build/plugins/index.js.map +1 -1
- package/build/plugins/persistence/index.js +13 -37
- package/build/plugins/persistence/index.js.map +1 -1
- package/build/plugins/persistence/storage/default.js +1 -5
- package/build/plugins/persistence/storage/default.js.map +1 -1
- package/build/plugins/persistence/storage/object.js +0 -5
- package/build/plugins/persistence/storage/object.js.map +1 -1
- package/build/promise-middleware.js +0 -5
- package/build/promise-middleware.js.map +1 -1
- package/build/redux-store/index.js +36 -117
- package/build/redux-store/index.js.map +1 -1
- package/build/redux-store/metadata/actions.js +8 -17
- package/build/redux-store/metadata/actions.js.map +1 -1
- package/build/redux-store/metadata/equivalent-key-map.d.js.map +1 -1
- package/build/redux-store/metadata/reducer.js +1 -23
- package/build/redux-store/metadata/reducer.js.map +1 -1
- package/build/redux-store/metadata/selectors.js +8 -22
- package/build/redux-store/metadata/selectors.js.map +1 -1
- package/build/redux-store/metadata/utils.js +6 -14
- package/build/redux-store/metadata/utils.js.map +1 -1
- package/build/redux-store/thunk-middleware.js +0 -2
- package/build/redux-store/thunk-middleware.js.map +1 -1
- package/build/registry.js +29 -73
- package/build/registry.js.map +1 -1
- package/build/resolvers-cache-middleware.js +2 -8
- package/build/resolvers-cache-middleware.js.map +1 -1
- package/build/select.js +0 -3
- package/build/select.js.map +1 -1
- package/build/store/index.js +0 -7
- package/build/store/index.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build/utils/emitter.js +2 -11
- package/build/utils/emitter.js.map +1 -1
- package/build-module/components/async-mode-provider/context.js +1 -1
- package/build-module/components/async-mode-provider/context.js.map +1 -1
- package/build-module/components/async-mode-provider/index.js.map +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.js +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.js.map +1 -1
- package/build-module/components/registry-provider/context.js +3 -3
- package/build-module/components/registry-provider/context.js.map +1 -1
- package/build-module/components/registry-provider/index.js.map +1 -1
- package/build-module/components/registry-provider/use-registry.js +2 -2
- package/build-module/components/registry-provider/use-registry.js.map +1 -1
- package/build-module/components/use-dispatch/index.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.js +2 -4
- package/build-module/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch.js +1 -3
- package/build-module/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build-module/components/use-select/index.js +35 -46
- package/build-module/components/use-select/index.js.map +1 -1
- package/build-module/components/with-dispatch/index.js +4 -6
- package/build-module/components/with-dispatch/index.js.map +1 -1
- package/build-module/components/with-registry/index.js +4 -4
- package/build-module/components/with-registry/index.js.map +1 -1
- package/build-module/components/with-select/index.js +4 -6
- package/build-module/components/with-select/index.js.map +1 -1
- package/build-module/controls.js +4 -8
- package/build-module/controls.js.map +1 -1
- package/build-module/default-registry.js.map +1 -1
- package/build-module/dispatch.js +2 -1
- package/build-module/dispatch.js.map +1 -1
- package/build-module/factory.js +2 -3
- package/build-module/factory.js.map +1 -1
- package/build-module/index.js +11 -10
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/plugins/index.js.map +1 -1
- package/build-module/plugins/persistence/index.js +15 -30
- package/build-module/plugins/persistence/index.js.map +1 -1
- package/build-module/plugins/persistence/storage/default.js +0 -2
- package/build-module/plugins/persistence/storage/default.js.map +1 -1
- package/build-module/plugins/persistence/storage/object.js +0 -5
- package/build-module/plugins/persistence/storage/object.js.map +1 -1
- package/build-module/promise-middleware.js +1 -3
- package/build-module/promise-middleware.js.map +1 -1
- package/build-module/redux-store/index.js +38 -101
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/redux-store/metadata/actions.js +8 -8
- package/build-module/redux-store/metadata/actions.js.map +1 -1
- package/build-module/redux-store/metadata/equivalent-key-map.d.js.map +1 -1
- package/build-module/redux-store/metadata/reducer.js +1 -21
- package/build-module/redux-store/metadata/reducer.js.map +1 -1
- package/build-module/redux-store/metadata/selectors.js +9 -13
- package/build-module/redux-store/metadata/selectors.js.map +1 -1
- package/build-module/redux-store/metadata/utils.js +6 -11
- package/build-module/redux-store/metadata/utils.js.map +1 -1
- package/build-module/redux-store/thunk-middleware.js +0 -1
- package/build-module/redux-store/thunk-middleware.js.map +1 -1
- package/build-module/registry.js +30 -67
- package/build-module/registry.js.map +1 -1
- package/build-module/resolvers-cache-middleware.js +3 -6
- package/build-module/resolvers-cache-middleware.js.map +1 -1
- package/build-module/select.js +2 -1
- package/build-module/select.js.map +1 -1
- package/build-module/store/index.js +0 -7
- package/build-module/store/index.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-module/utils/emitter.js +2 -10
- package/build-module/utils/emitter.js.map +1 -1
- package/build-types/components/use-select/index.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/plugins/persistence/index.d.ts.map +1 -1
- package/build-types/store/index.d.ts +1 -1
- package/package.json +9 -9
- package/src/components/use-select/index.js +14 -0
- package/src/plugins/persistence/index.js +0 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_store","_interopRequireDefault","require","createResolversCacheMiddleware","registry","reducerKey","next","action","resolvers","select","coreDataStore","getCachedResolvers","Object","entries","forEach","selectorName","resolversByArgs","resolver","stores","shouldInvalidate","value","args","status","dispatch","invalidateResolution","_default","exports","default"],"sources":["@wordpress/data/src/resolvers-cache-middleware.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport coreDataStore from './store';\n\n/** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */\n\n/**\n * Creates a middleware handling resolvers cache invalidation.\n *\n * @param {WPDataRegistry} registry The registry reference for which to create\n * the middleware.\n * @param {string} reducerKey The namespace for which to create the\n * middleware.\n *\n * @return {Function} Middleware function.\n */\nconst createResolversCacheMiddleware =\n\t( registry, reducerKey ) => () => ( next ) => ( action ) => {\n\t\tconst resolvers = registry\n\t\t\t.select( coreDataStore )\n\t\t\t.getCachedResolvers( reducerKey );\n\t\tObject.entries( resolvers ).forEach(\n\t\t\t( [ selectorName, resolversByArgs ] ) => {\n\t\t\t\tconst resolver =\n\t\t\t\t\tregistry.stores?.[ reducerKey ]?.resolvers?.[\n\t\t\t\t\t\tselectorName\n\t\t\t\t\t];\n\t\t\t\tif ( ! resolver || ! resolver.shouldInvalidate ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tresolversByArgs.forEach( ( value, args ) => {\n\t\t\t\t\t// resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector.\n\t\t\t\t\t// If the value is \"finished\" or \"error\" it means this resolver has finished its resolution which means we need\n\t\t\t\t\t// to invalidate it, if it's true it means it's inflight and the invalidation is not necessary.\n\t\t\t\t\tif (\n\t\t\t\t\t\t( value?.status !== 'finished' &&\n\t\t\t\t\t\t\tvalue?.status !== 'error' ) ||\n\t\t\t\t\t\t! resolver.shouldInvalidate( action, ...args )\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Trigger cache invalidation\n\t\t\t\t\tregistry\n\t\t\t\t\t\t.dispatch( coreDataStore )\n\t\t\t\t\t\t.invalidateResolution( reducerKey, selectorName, args );\n\t\t\t\t} );\n\t\t\t}\n\t\t);\n\t\treturn next( action );\n\t};\n\nexport default createResolversCacheMiddleware;\n"],"mappings":";;;;;;;AAGA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,8BAA8B,GACnCA,CAAEC,QAAQ,EAAEC,UAAU,KAAM,MAAQC,IAAI,IAAQC,MAAM,IAAM;EAC3D,MAAMC,SAAS,GAAGJ,QAAQ,CACxBK,MAAM,CAAEC,cAAc,CAAC,CACvBC,kBAAkB,CAAEN,UAAW,CAAC;EAClCO,MAAM,CAACC,OAAO,CAAEL,SAAU,CAAC,CAACM,OAAO,CAClC,CAAE,CAAEC,YAAY,EAAEC,eAAe,CAAE,KAAM;IACxC,MAAMC,QAAQ,GACbb,QAAQ,CAACc,MAAM,GAAIb,UAAU,CAAE,EAAEG,SAAS,GACzCO,YAAY,CACZ;IACF,IAAK,CAAEE,QAAQ,IAAI,CAAEA,QAAQ,CAACE,gBAAgB,EAAG;MAChD;IACD;IACAH,eAAe,CAACF,OAAO,CAAE,CAAEM,KAAK,EAAEC,IAAI,KAAM;MAC3C;MACA;MACA;MACA,IACGD,KAAK,EAAEE,MAAM,KAAK,UAAU,IAC7BF,KAAK,EAAEE,MAAM,KAAK,OAAO,IAC1B,CAAEL,QAAQ,CAACE,gBAAgB,CAAEZ,MAAM,EAAE,GAAGc,IAAK,CAAC,EAC7C;QACD;MACD;;MAEA;MACAjB,QAAQ,CACNmB,QAAQ,CAAEb,cAAc,CAAC,CACzBc,oBAAoB,CAAEnB,UAAU,EAAEU,YAAY,EAAEM,IAAK,CAAC;IACzD,CAAE,CAAC;EACJ,CACD,CAAC;EACD,OAAOf,IAAI,CAAEC,MAAO,CAAC;AACtB,CAAC;AAAC,IAAAkB,QAAA,GAEYtB,8BAA8B;AAAAuB,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
package/build/select.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.select = select;
|
|
9
|
-
|
|
10
8
|
var _defaultRegistry = _interopRequireDefault(require("./default-registry"));
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Internal dependencies
|
|
14
11
|
*/
|
package/build/select.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_defaultRegistry","_interopRequireDefault","require","select","storeNameOrDescriptor","defaultRegistry"],"sources":["@wordpress/data/src/select.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { AnyConfig, CurriedSelectorsOf, StoreDescriptor } from './types';\nimport defaultRegistry from './default-registry';\n\n/**\n * Given a store descriptor, returns an object of the store's selectors.\n * The selector functions are been pre-bound to pass the current state automatically.\n * As a consumer, you need only pass arguments of the selector, if applicable.\n *\n *\n * @param storeNameOrDescriptor The store descriptor. The legacy calling convention\n * of passing the store name is also supported.\n *\n * @example\n * ```js\n * import { select } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * select( myCustomStore ).getPrice( 'hammer' );\n * ```\n *\n * @return Object containing the store's selectors.\n */\nexport function select< T extends StoreDescriptor< AnyConfig > >(\n\tstoreNameOrDescriptor: string | T\n): CurriedSelectorsOf< T > {\n\treturn defaultRegistry.select( storeNameOrDescriptor );\n}\n"],"mappings":";;;;;;;AAIA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,MAAMA,CACrBC,qBAAiC,EACP;EAC1B,OAAOC,wBAAe,CAACF,MAAM,CAAEC,qBAAsB,CAAC;AACvD"}
|
package/build/store/index.js
CHANGED
|
@@ -6,25 +6,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
const coreDataStore = {
|
|
8
8
|
name: 'core/data',
|
|
9
|
-
|
|
10
9
|
instantiate(registry) {
|
|
11
10
|
const getCoreDataSelector = selectorName => (key, ...args) => {
|
|
12
11
|
return registry.select(key)[selectorName](...args);
|
|
13
12
|
};
|
|
14
|
-
|
|
15
13
|
const getCoreDataAction = actionName => (key, ...args) => {
|
|
16
14
|
return registry.dispatch(key)[actionName](...args);
|
|
17
15
|
};
|
|
18
|
-
|
|
19
16
|
return {
|
|
20
17
|
getSelectors() {
|
|
21
18
|
return Object.fromEntries(['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'].map(selectorName => [selectorName, getCoreDataSelector(selectorName)]));
|
|
22
19
|
},
|
|
23
|
-
|
|
24
20
|
getActions() {
|
|
25
21
|
return Object.fromEntries(['startResolution', 'finishResolution', 'invalidateResolution', 'invalidateResolutionForStore', 'invalidateResolutionForStoreSelector'].map(actionName => [actionName, getCoreDataAction(actionName)]));
|
|
26
22
|
},
|
|
27
|
-
|
|
28
23
|
subscribe() {
|
|
29
24
|
// There's no reasons to trigger any listener when we subscribe to this store
|
|
30
25
|
// because there's no state stored in this store that need to retrigger selectors
|
|
@@ -32,10 +27,8 @@ const coreDataStore = {
|
|
|
32
27
|
// would have already triggered a "subscribe" call.
|
|
33
28
|
return () => () => {};
|
|
34
29
|
}
|
|
35
|
-
|
|
36
30
|
};
|
|
37
31
|
}
|
|
38
|
-
|
|
39
32
|
};
|
|
40
33
|
var _default = coreDataStore;
|
|
41
34
|
exports.default = _default;
|
package/build/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["coreDataStore","name","instantiate","registry","getCoreDataSelector","selectorName","key","args","select","getCoreDataAction","actionName","dispatch","getSelectors","Object","fromEntries","map","getActions","subscribe","_default","exports","default"],"sources":["@wordpress/data/src/store/index.js"],"sourcesContent":["const coreDataStore = {\n\tname: 'core/data',\n\tinstantiate( registry ) {\n\t\tconst getCoreDataSelector =\n\t\t\t( selectorName ) =>\n\t\t\t( key, ...args ) => {\n\t\t\t\treturn registry.select( key )[ selectorName ]( ...args );\n\t\t\t};\n\n\t\tconst getCoreDataAction =\n\t\t\t( actionName ) =>\n\t\t\t( key, ...args ) => {\n\t\t\t\treturn registry.dispatch( key )[ actionName ]( ...args );\n\t\t\t};\n\n\t\treturn {\n\t\t\tgetSelectors() {\n\t\t\t\treturn Object.fromEntries(\n\t\t\t\t\t[\n\t\t\t\t\t\t'getIsResolving',\n\t\t\t\t\t\t'hasStartedResolution',\n\t\t\t\t\t\t'hasFinishedResolution',\n\t\t\t\t\t\t'isResolving',\n\t\t\t\t\t\t'getCachedResolvers',\n\t\t\t\t\t].map( ( selectorName ) => [\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\tgetCoreDataSelector( selectorName ),\n\t\t\t\t\t] )\n\t\t\t\t);\n\t\t\t},\n\n\t\t\tgetActions() {\n\t\t\t\treturn Object.fromEntries(\n\t\t\t\t\t[\n\t\t\t\t\t\t'startResolution',\n\t\t\t\t\t\t'finishResolution',\n\t\t\t\t\t\t'invalidateResolution',\n\t\t\t\t\t\t'invalidateResolutionForStore',\n\t\t\t\t\t\t'invalidateResolutionForStoreSelector',\n\t\t\t\t\t].map( ( actionName ) => [\n\t\t\t\t\t\tactionName,\n\t\t\t\t\t\tgetCoreDataAction( actionName ),\n\t\t\t\t\t] )\n\t\t\t\t);\n\t\t\t},\n\n\t\t\tsubscribe() {\n\t\t\t\t// There's no reasons to trigger any listener when we subscribe to this store\n\t\t\t\t// because there's no state stored in this store that need to retrigger selectors\n\t\t\t\t// if a change happens, the corresponding store where the tracking stated live\n\t\t\t\t// would have already triggered a \"subscribe\" call.\n\t\t\t\treturn () => () => {};\n\t\t\t},\n\t\t};\n\t},\n};\n\nexport default coreDataStore;\n"],"mappings":";;;;;;AAAA,MAAMA,aAAa,GAAG;EACrBC,IAAI,EAAE,WAAW;EACjBC,WAAWA,CAAEC,QAAQ,EAAG;IACvB,MAAMC,mBAAmB,GACtBC,YAAY,IACd,CAAEC,GAAG,EAAE,GAAGC,IAAI,KAAM;MACnB,OAAOJ,QAAQ,CAACK,MAAM,CAAEF,GAAI,CAAC,CAAED,YAAY,CAAE,CAAE,GAAGE,IAAK,CAAC;IACzD,CAAC;IAEF,MAAME,iBAAiB,GACpBC,UAAU,IACZ,CAAEJ,GAAG,EAAE,GAAGC,IAAI,KAAM;MACnB,OAAOJ,QAAQ,CAACQ,QAAQ,CAAEL,GAAI,CAAC,CAAEI,UAAU,CAAE,CAAE,GAAGH,IAAK,CAAC;IACzD,CAAC;IAEF,OAAO;MACNK,YAAYA,CAAA,EAAG;QACd,OAAOC,MAAM,CAACC,WAAW,CACxB,CACC,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,oBAAoB,CACpB,CAACC,GAAG,CAAIV,YAAY,IAAM,CAC1BA,YAAY,EACZD,mBAAmB,CAAEC,YAAa,CAAC,CAClC,CACH,CAAC;MACF,CAAC;MAEDW,UAAUA,CAAA,EAAG;QACZ,OAAOH,MAAM,CAACC,WAAW,CACxB,CACC,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,8BAA8B,EAC9B,sCAAsC,CACtC,CAACC,GAAG,CAAIL,UAAU,IAAM,CACxBA,UAAU,EACVD,iBAAiB,CAAEC,UAAW,CAAC,CAC9B,CACH,CAAC;MACF,CAAC;MAEDO,SAASA,CAAA,EAAG;QACX;QACA;QACA;QACA;QACA,OAAO,MAAM,MAAM,CAAC,CAAC;MACtB;IACD,CAAC;EACF;AACD,CAAC;AAAC,IAAAC,QAAA,GAEalB,aAAa;AAAAmB,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
package/build/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/data/src/types.ts"],"sourcesContent":["/**\n * External dependencies\n */\n// eslint-disable-next-line no-restricted-imports\nimport type { combineReducers as reduxCombineReducers } from 'redux';\n\ntype MapOf< T > = { [ name: string ]: T };\n\nexport type ActionCreator = ( ...args: any[] ) => any | Generator;\nexport type Resolver = Function | Generator;\nexport type Selector = Function;\n\nexport type AnyConfig = ReduxStoreConfig< any, any, any >;\n\nexport interface StoreInstance< Config extends AnyConfig > {\n\tgetSelectors: () => SelectorsOf< Config >;\n\tgetActions: () => ActionCreatorsOf< Config >;\n\tsubscribe: ( listener: () => void ) => () => void;\n}\n\nexport interface StoreDescriptor< Config extends AnyConfig > {\n\t/**\n\t * Store Name\n\t */\n\tname: string;\n\n\t/**\n\t * Creates a store instance\n\t */\n\tinstantiate: ( registry: DataRegistry ) => StoreInstance< Config >;\n}\n\nexport interface ReduxStoreConfig<\n\tState,\n\tActionCreators extends MapOf< ActionCreator >,\n\tSelectors\n> {\n\tinitialState?: State;\n\treducer: ( state: any, action: any ) => any;\n\tactions?: ActionCreators;\n\tresolvers?: MapOf< Resolver >;\n\tselectors?: Selectors;\n\tcontrols?: MapOf< Function >;\n}\n\n// Return type for the useSelect() hook.\nexport type UseSelectReturn< F extends MapSelect | StoreDescriptor< any > > =\n\tF extends MapSelect\n\t\t? ReturnType< F >\n\t\t: F extends StoreDescriptor< any >\n\t\t? CurriedSelectorsOf< F >\n\t\t: never;\n\n// Return type for the useDispatch() hook.\nexport type UseDispatchReturn< StoreNameOrDescriptor > =\n\tStoreNameOrDescriptor extends StoreDescriptor< any >\n\t\t? ActionCreatorsOf< ConfigOf< StoreNameOrDescriptor > >\n\t\t: StoreNameOrDescriptor extends undefined\n\t\t? DispatchFunction\n\t\t: any;\n\nexport type DispatchFunction = < StoreNameOrDescriptor >(\n\tstore: StoreNameOrDescriptor\n) => DispatchReturn< StoreNameOrDescriptor >;\n\nexport type DispatchReturn< StoreNameOrDescriptor > =\n\tStoreNameOrDescriptor extends StoreDescriptor< any >\n\t\t? ActionCreatorsOf< ConfigOf< StoreNameOrDescriptor > >\n\t\t: unknown;\n\nexport type MapSelect = (\n\tselect: SelectFunction,\n\tregistry: DataRegistry\n) => any;\n\nexport type SelectFunction = < S >( store: S ) => CurriedSelectorsOf< S >;\n\n/**\n * Callback for store's `subscribe()` method that\n * runs when the store data has changed.\n */\nexport type ListenerFunction = () => void;\n\nexport type CurriedSelectorsOf< S > = S extends StoreDescriptor<\n\tReduxStoreConfig< any, any, infer Selectors >\n>\n\t? { [ key in keyof Selectors ]: CurriedState< Selectors[ key ] > }\n\t: never;\n\n/**\n * Removes the first argument from a function.\n *\n * By default, it removes the `state` parameter from\n * registered selectors since that argument is supplied\n * by the editor when calling `select(…)`.\n *\n * For functions with no arguments, which some selectors\n * are free to define, returns the original function.\n *\n * It is possible to manually provide a custom curried signature\n * and avoid the automatic inference. When the\n * F generic argument passed to this helper extends the\n * SelectorWithCustomCurrySignature type, the F['CurriedSignature']\n * property is used verbatim.\n *\n * This is useful because TypeScript does not correctly remove\n * arguments from complex function signatures constrained by\n * interdependent generic parameters.\n * For more context, see https://github.com/WordPress/gutenberg/pull/41578\n */\ntype CurriedState< F > = F extends SelectorWithCustomCurrySignature\n\t? F[ 'CurriedSignature' ]\n\t: F extends ( state: any, ...args: infer P ) => infer R\n\t? ( ...args: P ) => R\n\t: F;\n\n/**\n * Utility to manually specify curried selector signatures.\n *\n * It comes handy when TypeScript can't automatically produce the\n * correct curried function signature. For example:\n *\n * ```ts\n * type BadlyInferredSignature = CurriedState<\n * <K extends string | number>(\n * state: any,\n * kind: K,\n * key: K extends string ? 'one value' : false\n * ) => K\n * >\n * // BadlyInferredSignature evaluates to:\n * // (kind: string number, key: false \"one value\") => string number\n * ```\n *\n * With SelectorWithCustomCurrySignature, we can provide a custom\n * signature and avoid relying on TypeScript inference:\n * ```ts\n * interface MySelectorSignature extends SelectorWithCustomCurrySignature {\n * <K extends string | number>(\n * state: any,\n * kind: K,\n * key: K extends string ? 'one value' : false\n * ): K;\n *\n * CurriedSignature: <K extends string | number>(\n * kind: K,\n * key: K extends string ? 'one value' : false\n * ): K;\n * }\n * type CorrectlyInferredSignature = CurriedState<MySelectorSignature>\n * // <K extends string | number>(kind: K, key: K extends string ? 'one value' : false): K;\n *\n * For even more context, see https://github.com/WordPress/gutenberg/pull/41578\n * ```\n */\nexport interface SelectorWithCustomCurrySignature {\n\tCurriedSignature: Function;\n}\n\nexport interface DataRegistry {\n\tregister: ( store: StoreDescriptor< any > ) => void;\n}\n\nexport interface DataEmitter {\n\temit: () => void;\n\tsubscribe: ( listener: () => void ) => () => void;\n\tpause: () => void;\n\tresume: () => void;\n\tisPaused: boolean;\n}\n\n// Type Helpers.\n\nexport type ConfigOf< S > = S extends StoreDescriptor< infer C > ? C : never;\n\nexport type ActionCreatorsOf< Config extends AnyConfig > =\n\tConfig extends ReduxStoreConfig< any, infer ActionCreators, any >\n\t\t? PromisifiedActionCreators< ActionCreators >\n\t\t: never;\n\n// Takes an object containing all action creators for a store and updates the\n// return type of each action creator to account for internal registry details --\n// for example, dispatched actions are wrapped with a Promise.\nexport type PromisifiedActionCreators<\n\tActionCreators extends MapOf< ActionCreator >\n> = {\n\t[ Action in keyof ActionCreators ]: PromisifyActionCreator<\n\t\tActionCreators[ Action ]\n\t>;\n};\n\n// Wraps action creator return types with a Promise and handles thunks.\nexport type PromisifyActionCreator< Action extends ActionCreator > = (\n\t...args: Parameters< Action >\n) => Promise<\n\tReturnType< Action > extends ( ..._args: any[] ) => any\n\t\t? ThunkReturnType< Action >\n\t\t: ReturnType< Action >\n>;\n\n// A thunk is an action creator which returns a function, which can optionally\n// return a Promise. The double ReturnType unwraps the innermost function's\n// return type, and Awaited gets the type the Promise resolves to. If the return\n// type is not a Promise, Awaited returns that original type.\nexport type ThunkReturnType< Action extends ActionCreator > = Awaited<\n\tReturnType< ReturnType< Action > >\n>;\n\ntype SelectorsOf< Config extends AnyConfig > = Config extends ReduxStoreConfig<\n\tany,\n\tany,\n\tinfer Selectors\n>\n\t? { [ name in keyof Selectors ]: Function }\n\t: never;\n\nexport type combineReducers = typeof reduxCombineReducers;\n"],"mappings":""}
|
package/build/utils/emitter.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createEmitter = createEmitter;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Create an event emitter.
|
|
10
9
|
*
|
|
@@ -14,44 +13,36 @@ function createEmitter() {
|
|
|
14
13
|
let isPaused = false;
|
|
15
14
|
let isPending = false;
|
|
16
15
|
const listeners = new Set();
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const notifyListeners = () =>
|
|
17
|
+
// We use Array.from to clone the listeners Set
|
|
19
18
|
// This ensures that we don't run a listener
|
|
20
19
|
// that was added as a response to another listener.
|
|
21
20
|
Array.from(listeners).forEach(listener => listener());
|
|
22
|
-
|
|
23
21
|
return {
|
|
24
22
|
get isPaused() {
|
|
25
23
|
return isPaused;
|
|
26
24
|
},
|
|
27
|
-
|
|
28
25
|
subscribe(listener) {
|
|
29
26
|
listeners.add(listener);
|
|
30
27
|
return () => listeners.delete(listener);
|
|
31
28
|
},
|
|
32
|
-
|
|
33
29
|
pause() {
|
|
34
30
|
isPaused = true;
|
|
35
31
|
},
|
|
36
|
-
|
|
37
32
|
resume() {
|
|
38
33
|
isPaused = false;
|
|
39
|
-
|
|
40
34
|
if (isPending) {
|
|
41
35
|
isPending = false;
|
|
42
36
|
notifyListeners();
|
|
43
37
|
}
|
|
44
38
|
},
|
|
45
|
-
|
|
46
39
|
emit() {
|
|
47
40
|
if (isPaused) {
|
|
48
41
|
isPending = true;
|
|
49
42
|
return;
|
|
50
43
|
}
|
|
51
|
-
|
|
52
44
|
notifyListeners();
|
|
53
45
|
}
|
|
54
|
-
|
|
55
46
|
};
|
|
56
47
|
}
|
|
57
48
|
//# sourceMappingURL=emitter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createEmitter","isPaused","isPending","listeners","Set","notifyListeners","Array","from","forEach","listener","subscribe","add","delete","pause","resume","emit"],"sources":["@wordpress/data/src/utils/emitter.js"],"sourcesContent":["/**\n * Create an event emitter.\n *\n * @return {import(\"../types\").DataEmitter} Emitter.\n */\nexport function createEmitter() {\n\tlet isPaused = false;\n\tlet isPending = false;\n\tconst listeners = new Set();\n\tconst notifyListeners = () =>\n\t\t// We use Array.from to clone the listeners Set\n\t\t// This ensures that we don't run a listener\n\t\t// that was added as a response to another listener.\n\t\tArray.from( listeners ).forEach( ( listener ) => listener() );\n\n\treturn {\n\t\tget isPaused() {\n\t\t\treturn isPaused;\n\t\t},\n\n\t\tsubscribe( listener ) {\n\t\t\tlisteners.add( listener );\n\t\t\treturn () => listeners.delete( listener );\n\t\t},\n\n\t\tpause() {\n\t\t\tisPaused = true;\n\t\t},\n\n\t\tresume() {\n\t\t\tisPaused = false;\n\t\t\tif ( isPending ) {\n\t\t\t\tisPending = false;\n\t\t\t\tnotifyListeners();\n\t\t\t}\n\t\t},\n\n\t\temit() {\n\t\t\tif ( isPaused ) {\n\t\t\t\tisPending = true;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tnotifyListeners();\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACO,SAASA,aAAaA,CAAA,EAAG;EAC/B,IAAIC,QAAQ,GAAG,KAAK;EACpB,IAAIC,SAAS,GAAG,KAAK;EACrB,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAAC,CAAC;EAC3B,MAAMC,eAAe,GAAGA,CAAA;EACvB;EACA;EACA;EACAC,KAAK,CAACC,IAAI,CAAEJ,SAAU,CAAC,CAACK,OAAO,CAAIC,QAAQ,IAAMA,QAAQ,CAAC,CAAE,CAAC;EAE9D,OAAO;IACN,IAAIR,QAAQA,CAAA,EAAG;MACd,OAAOA,QAAQ;IAChB,CAAC;IAEDS,SAASA,CAAED,QAAQ,EAAG;MACrBN,SAAS,CAACQ,GAAG,CAAEF,QAAS,CAAC;MACzB,OAAO,MAAMN,SAAS,CAACS,MAAM,CAAEH,QAAS,CAAC;IAC1C,CAAC;IAEDI,KAAKA,CAAA,EAAG;MACPZ,QAAQ,GAAG,IAAI;IAChB,CAAC;IAEDa,MAAMA,CAAA,EAAG;MACRb,QAAQ,GAAG,KAAK;MAChB,IAAKC,SAAS,EAAG;QAChBA,SAAS,GAAG,KAAK;QACjBG,eAAe,CAAC,CAAC;MAClB;IACD,CAAC;IAEDU,IAAIA,CAAA,EAAG;MACN,IAAKd,QAAQ,EAAG;QACfC,SAAS,GAAG,IAAI;QAChB;MACD;MACAG,eAAe,CAAC,CAAC;IAClB;EACD,CAAC;AACF"}
|
|
@@ -8,6 +8,7 @@ const {
|
|
|
8
8
|
Provider
|
|
9
9
|
} = Context;
|
|
10
10
|
export const AsyncModeConsumer = Consumer;
|
|
11
|
+
|
|
11
12
|
/**
|
|
12
13
|
* Context Provider Component used to switch the data module component rerendering
|
|
13
14
|
* between Sync and Async modes.
|
|
@@ -43,6 +44,5 @@ export const AsyncModeConsumer = Consumer;
|
|
|
43
44
|
* @param {boolean} props.value Enable Async Mode.
|
|
44
45
|
* @return {WPComponent} The component to be rendered.
|
|
45
46
|
*/
|
|
46
|
-
|
|
47
47
|
export default Provider;
|
|
48
48
|
//# sourceMappingURL=context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createContext","Context","Consumer","Provider","AsyncModeConsumer"],"sources":["@wordpress/data/src/components/async-mode-provider/context.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext } from '@wordpress/element';\n\nexport const Context = createContext( false );\n\nconst { Consumer, Provider } = Context;\n\nexport const AsyncModeConsumer = Consumer;\n\n/**\n * Context Provider Component used to switch the data module component rerendering\n * between Sync and Async modes.\n *\n * @example\n *\n * ```js\n * import { useSelect, AsyncModeProvider } from '@wordpress/data';\n * import { store as blockEditorStore } from '@wordpress/block-editor';\n *\n * function BlockCount() {\n * const count = useSelect( ( select ) => {\n * return select( blockEditorStore ).getBlockCount()\n * }, [] );\n *\n * return count;\n * }\n *\n * function App() {\n * return (\n * <AsyncModeProvider value={ true }>\n * <BlockCount />\n * </AsyncModeProvider>\n * );\n * }\n * ```\n *\n * In this example, the BlockCount component is rerendered asynchronously.\n * It means if a more critical task is being performed (like typing in an input),\n * the rerendering is delayed until the browser becomes IDLE.\n * It is possible to nest multiple levels of AsyncModeProvider to fine-tune the rendering behavior.\n *\n * @param {boolean} props.value Enable Async Mode.\n * @return {WPComponent} The component to be rendered.\n */\nexport default Provider;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,aAAa,QAAQ,oBAAoB;AAElD,OAAO,MAAMC,OAAO,GAAGD,aAAa,CAAE,KAAM,CAAC;AAE7C,MAAM;EAAEE,QAAQ;EAAEC;AAAS,CAAC,GAAGF,OAAO;AAEtC,OAAO,MAAMG,iBAAiB,GAAGF,QAAQ;;AAEzC;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,eAAeC,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["default","useAsyncMode","AsyncModeProvider","AsyncModeConsumer"],"sources":["@wordpress/data/src/components/async-mode-provider/index.js"],"sourcesContent":["export { default as useAsyncMode } from './use-async-mode';\nexport { default as AsyncModeProvider, AsyncModeConsumer } from './context';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,YAAY,QAAQ,kBAAkB;AAC1D,SAASD,OAAO,IAAIE,iBAAiB,EAAEC,iBAAiB,QAAQ,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/async-mode-provider/use-async-mode.js"],"
|
|
1
|
+
{"version":3,"names":["useContext","Context","useAsyncMode"],"sources":["@wordpress/data/src/components/async-mode-provider/use-async-mode.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { Context } from './context';\n\nexport default function useAsyncMode() {\n\treturn useContext( Context );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,oBAAoB;;AAE/C;AACA;AACA;AACA,SAASC,OAAO,QAAQ,WAAW;AAEnC,eAAe,SAASC,YAAYA,CAAA,EAAG;EACtC,OAAOF,UAAU,CAAEC,OAAQ,CAAC;AAC7B"}
|
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { createContext } from '@wordpress/element';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Internal dependencies
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
9
|
import defaultRegistry from '../../default-registry';
|
|
10
10
|
export const Context = createContext(defaultRegistry);
|
|
11
11
|
const {
|
|
12
12
|
Consumer,
|
|
13
13
|
Provider
|
|
14
14
|
} = Context;
|
|
15
|
+
|
|
15
16
|
/**
|
|
16
17
|
* A custom react Context consumer exposing the provided `registry` to
|
|
17
18
|
* children components. Used along with the RegistryProvider.
|
|
@@ -43,8 +44,8 @@ const {
|
|
|
43
44
|
* }
|
|
44
45
|
* ```
|
|
45
46
|
*/
|
|
46
|
-
|
|
47
47
|
export const RegistryConsumer = Consumer;
|
|
48
|
+
|
|
48
49
|
/**
|
|
49
50
|
* A custom Context provider for exposing the provided `registry` to children
|
|
50
51
|
* components via a consumer.
|
|
@@ -52,6 +53,5 @@ export const RegistryConsumer = Consumer;
|
|
|
52
53
|
* See <a name="#RegistryConsumer">RegistryConsumer</a> documentation for
|
|
53
54
|
* example.
|
|
54
55
|
*/
|
|
55
|
-
|
|
56
56
|
export default Provider;
|
|
57
57
|
//# sourceMappingURL=context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createContext","defaultRegistry","Context","Consumer","Provider","RegistryConsumer"],"sources":["@wordpress/data/src/components/registry-provider/context.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport defaultRegistry from '../../default-registry';\n\nexport const Context = createContext( defaultRegistry );\n\nconst { Consumer, Provider } = Context;\n\n/**\n * A custom react Context consumer exposing the provided `registry` to\n * children components. Used along with the RegistryProvider.\n *\n * You can read more about the react context api here:\n * https://reactjs.org/docs/context.html#contextprovider\n *\n * @example\n * ```js\n * import {\n * RegistryProvider,\n * RegistryConsumer,\n * createRegistry\n * } from '@wordpress/data';\n *\n * const registry = createRegistry( {} );\n *\n * const App = ( { props } ) => {\n * return <RegistryProvider value={ registry }>\n * <div>Hello There</div>\n * <RegistryConsumer>\n * { ( registry ) => (\n * <ComponentUsingRegistry\n * \t\t{ ...props }\n * \t registry={ registry }\n * ) }\n * </RegistryConsumer>\n * </RegistryProvider>\n * }\n * ```\n */\nexport const RegistryConsumer = Consumer;\n\n/**\n * A custom Context provider for exposing the provided `registry` to children\n * components via a consumer.\n *\n * See <a name=\"#RegistryConsumer\">RegistryConsumer</a> documentation for\n * example.\n */\nexport default Provider;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,aAAa,QAAQ,oBAAoB;;AAElD;AACA;AACA;AACA,OAAOC,eAAe,MAAM,wBAAwB;AAEpD,OAAO,MAAMC,OAAO,GAAGF,aAAa,CAAEC,eAAgB,CAAC;AAEvD,MAAM;EAAEE,QAAQ;EAAEC;AAAS,CAAC,GAAGF,OAAO;;AAEtC;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,OAAO,MAAMG,gBAAgB,GAAGF,QAAQ;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAeC,QAAQ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["default","RegistryProvider","RegistryConsumer","useRegistry"],"sources":["@wordpress/data/src/components/registry-provider/index.js"],"sourcesContent":["export { default as RegistryProvider, RegistryConsumer } from './context';\nexport { default as useRegistry } from './use-registry';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,gBAAgB,EAAEC,gBAAgB,QAAQ,WAAW;AACzE,SAASF,OAAO,IAAIG,WAAW,QAAQ,gBAAgB"}
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useContext } from '@wordpress/element';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Internal dependencies
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
9
|
import { Context } from './context';
|
|
10
|
+
|
|
10
11
|
/**
|
|
11
12
|
* A custom react hook exposing the registry context for use.
|
|
12
13
|
*
|
|
@@ -46,7 +47,6 @@ import { Context } from './context';
|
|
|
46
47
|
*
|
|
47
48
|
* @return {Function} A custom react hook exposing the registry context value.
|
|
48
49
|
*/
|
|
49
|
-
|
|
50
50
|
export default function useRegistry() {
|
|
51
51
|
return useContext(Context);
|
|
52
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/registry-provider/use-registry.js"],"
|
|
1
|
+
{"version":3,"names":["useContext","Context","useRegistry"],"sources":["@wordpress/data/src/components/registry-provider/use-registry.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { Context } from './context';\n\n/**\n * A custom react hook exposing the registry context for use.\n *\n * This exposes the `registry` value provided via the\n * <a href=\"#RegistryProvider\">Registry Provider</a> to a component implementing\n * this hook.\n *\n * It acts similarly to the `useContext` react hook.\n *\n * Note: Generally speaking, `useRegistry` is a low level hook that in most cases\n * won't be needed for implementation. Most interactions with the `@wordpress/data`\n * API can be performed via the `useSelect` hook, or the `withSelect` and\n * `withDispatch` higher order components.\n *\n * @example\n * ```js\n * import {\n * RegistryProvider,\n * createRegistry,\n * useRegistry,\n * } from '@wordpress/data';\n *\n * const registry = createRegistry( {} );\n *\n * const SomeChildUsingRegistry = ( props ) => {\n * const registry = useRegistry();\n * // ...logic implementing the registry in other react hooks.\n * };\n *\n *\n * const ParentProvidingRegistry = ( props ) => {\n * return <RegistryProvider value={ registry }>\n * <SomeChildUsingRegistry { ...props } />\n * </RegistryProvider>\n * };\n * ```\n *\n * @return {Function} A custom react hook exposing the registry context value.\n */\nexport default function useRegistry() {\n\treturn useContext( Context );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,oBAAoB;;AAE/C;AACA;AACA;AACA,SAASC,OAAO,QAAQ,WAAW;;AAEnC;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;AACA,eAAe,SAASC,WAAWA,CAAA,EAAG;EACrC,OAAOF,UAAU,CAAEC,OAAQ,CAAC;AAC7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/use-dispatch/index.js"],"
|
|
1
|
+
{"version":3,"names":["default","useDispatch","useDispatchWithMap"],"sources":["@wordpress/data/src/components/use-dispatch/index.js"],"sourcesContent":["export { default as useDispatch } from './use-dispatch';\nexport { default as useDispatchWithMap } from './use-dispatch-with-map';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,WAAW,QAAQ,gBAAgB;AACvD,SAASD,OAAO,IAAIE,kBAAkB,QAAQ,yBAAyB"}
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { useMemo, useRef } from '@wordpress/element';
|
|
5
5
|
import { useIsomorphicLayoutEffect } from '@wordpress/compose';
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Internal dependencies
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
10
|
import useRegistry from '../registry-provider/use-registry';
|
|
11
|
+
|
|
11
12
|
/**
|
|
12
13
|
* Custom react hook for returning aggregate dispatch actions using the provided
|
|
13
14
|
* dispatchMap.
|
|
@@ -22,7 +23,6 @@ import useRegistry from '../registry-provider/use-registry';
|
|
|
22
23
|
* @return {Object} An object mapping props to functions created by the passed
|
|
23
24
|
* in dispatchMap.
|
|
24
25
|
*/
|
|
25
|
-
|
|
26
26
|
const useDispatchWithMap = (dispatchMap, deps) => {
|
|
27
27
|
const registry = useRegistry();
|
|
28
28
|
const currentDispatchMap = useRef(dispatchMap);
|
|
@@ -36,11 +36,9 @@ const useDispatchWithMap = (dispatchMap, deps) => {
|
|
|
36
36
|
// eslint-disable-next-line no-console
|
|
37
37
|
console.warn(`Property ${propName} returned from dispatchMap in useDispatchWithMap must be a function.`);
|
|
38
38
|
}
|
|
39
|
-
|
|
40
39
|
return [propName, (...args) => currentDispatchMap.current(registry.dispatch, registry)[propName](...args)];
|
|
41
40
|
}));
|
|
42
41
|
}, [registry, ...deps]);
|
|
43
42
|
};
|
|
44
|
-
|
|
45
43
|
export default useDispatchWithMap;
|
|
46
44
|
//# sourceMappingURL=use-dispatch-with-map.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useMemo","useRef","useIsomorphicLayoutEffect","useRegistry","useDispatchWithMap","dispatchMap","deps","registry","currentDispatchMap","current","currentDispatchProps","dispatch","Object","fromEntries","entries","map","propName","dispatcher","console","warn","args"],"sources":["@wordpress/data/src/components/use-dispatch/use-dispatch-with-map.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useRef } from '@wordpress/element';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\n\n/**\n * Custom react hook for returning aggregate dispatch actions using the provided\n * dispatchMap.\n *\n * Currently this is an internal api only and is implemented by `withDispatch`\n *\n * @param {Function} dispatchMap Receives the `registry.dispatch` function as\n * the first argument and the `registry` object\n * as the second argument. Should return an\n * object mapping props to functions.\n * @param {Array} deps An array of dependencies for the hook.\n * @return {Object} An object mapping props to functions created by the passed\n * in dispatchMap.\n */\nconst useDispatchWithMap = ( dispatchMap, deps ) => {\n\tconst registry = useRegistry();\n\tconst currentDispatchMap = useRef( dispatchMap );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tcurrentDispatchMap.current = dispatchMap;\n\t} );\n\n\treturn useMemo( () => {\n\t\tconst currentDispatchProps = currentDispatchMap.current(\n\t\t\tregistry.dispatch,\n\t\t\tregistry\n\t\t);\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries( currentDispatchProps ).map(\n\t\t\t\t( [ propName, dispatcher ] ) => {\n\t\t\t\t\tif ( typeof dispatcher !== 'function' ) {\n\t\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`Property ${ propName } returned from dispatchMap in useDispatchWithMap must be a function.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn [\n\t\t\t\t\t\tpropName,\n\t\t\t\t\t\t( ...args ) =>\n\t\t\t\t\t\t\tcurrentDispatchMap\n\t\t\t\t\t\t\t\t.current( registry.dispatch, registry )\n\t\t\t\t\t\t\t\t[ propName ]( ...args ),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t)\n\t\t);\n\t}, [ registry, ...deps ] );\n};\n\nexport default useDispatchWithMap;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,MAAM,QAAQ,oBAAoB;AACpD,SAASC,yBAAyB,QAAQ,oBAAoB;;AAE9D;AACA;AACA;AACA,OAAOC,WAAW,MAAM,mCAAmC;;AAE3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAGA,CAAEC,WAAW,EAAEC,IAAI,KAAM;EACnD,MAAMC,QAAQ,GAAGJ,WAAW,CAAC,CAAC;EAC9B,MAAMK,kBAAkB,GAAGP,MAAM,CAAEI,WAAY,CAAC;EAEhDH,yBAAyB,CAAE,MAAM;IAChCM,kBAAkB,CAACC,OAAO,GAAGJ,WAAW;EACzC,CAAE,CAAC;EAEH,OAAOL,OAAO,CAAE,MAAM;IACrB,MAAMU,oBAAoB,GAAGF,kBAAkB,CAACC,OAAO,CACtDF,QAAQ,CAACI,QAAQ,EACjBJ,QACD,CAAC;IACD,OAAOK,MAAM,CAACC,WAAW,CACxBD,MAAM,CAACE,OAAO,CAAEJ,oBAAqB,CAAC,CAACK,GAAG,CACzC,CAAE,CAAEC,QAAQ,EAAEC,UAAU,CAAE,KAAM;MAC/B,IAAK,OAAOA,UAAU,KAAK,UAAU,EAAG;QACvC;QACAC,OAAO,CAACC,IAAI,CACV,YAAYH,QAAU,sEACxB,CAAC;MACF;MACA,OAAO,CACNA,QAAQ,EACR,CAAE,GAAGI,IAAI,KACRZ,kBAAkB,CAChBC,OAAO,CAAEF,QAAQ,CAACI,QAAQ,EAAEJ,QAAS,CAAC,CACrCS,QAAQ,CAAE,CAAE,GAAGI,IAAK,CAAC,CACzB;IACF,CACD,CACD,CAAC;EACF,CAAC,EAAE,CAAEb,QAAQ,EAAE,GAAGD,IAAI,CAAG,CAAC;AAC3B,CAAC;AAED,eAAeF,kBAAkB"}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
4
|
import useRegistry from '../registry-provider/use-registry';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* @typedef {import('../../types').StoreDescriptor<StoreConfig>} StoreDescriptor
|
|
7
8
|
* @template {import('../../types').AnyConfig} StoreConfig
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
10
|
/**
|
|
11
11
|
* @typedef {import('../../types').UseDispatchReturn<StoreNameOrDescriptor>} UseDispatchReturn
|
|
12
12
|
* @template StoreNameOrDescriptor
|
|
@@ -58,13 +58,11 @@ import useRegistry from '../registry-provider/use-registry';
|
|
|
58
58
|
* ```
|
|
59
59
|
* @return {UseDispatchReturn<StoreNameOrDescriptor>} A custom react hook.
|
|
60
60
|
*/
|
|
61
|
-
|
|
62
61
|
const useDispatch = storeNameOrDescriptor => {
|
|
63
62
|
const {
|
|
64
63
|
dispatch
|
|
65
64
|
} = useRegistry();
|
|
66
65
|
return storeNameOrDescriptor === void 0 ? dispatch : dispatch(storeNameOrDescriptor);
|
|
67
66
|
};
|
|
68
|
-
|
|
69
67
|
export default useDispatch;
|
|
70
68
|
//# sourceMappingURL=use-dispatch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useRegistry","useDispatch","storeNameOrDescriptor","dispatch"],"sources":["@wordpress/data/src/components/use-dispatch/use-dispatch.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\n\n/**\n * @typedef {import('../../types').StoreDescriptor<StoreConfig>} StoreDescriptor\n * @template {import('../../types').AnyConfig} StoreConfig\n */\n/**\n * @typedef {import('../../types').UseDispatchReturn<StoreNameOrDescriptor>} UseDispatchReturn\n * @template StoreNameOrDescriptor\n */\n\n/**\n * A custom react hook returning the current registry dispatch actions creators.\n *\n * Note: The component using this hook must be within the context of a\n * RegistryProvider.\n *\n * @template {undefined | string | StoreDescriptor<any>} StoreNameOrDescriptor\n * @param {StoreNameOrDescriptor} [storeNameOrDescriptor] Optionally provide the name of the\n * store or its descriptor from which to\n * retrieve action creators. If not\n * provided, the registry.dispatch\n * function is returned instead.\n *\n * @example\n * This illustrates a pattern where you may need to retrieve dynamic data from\n * the server via the `useSelect` hook to use in combination with the dispatch\n * action.\n *\n * ```jsx\n * import { useDispatch, useSelect } from '@wordpress/data';\n * import { useCallback } from '@wordpress/element';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>\n * }\n *\n * const SaleButton = ( { children } ) => {\n * const { stockNumber } = useSelect(\n * ( select ) => select( myCustomStore ).getStockNumber(),\n * []\n * );\n * const { startSale } = useDispatch( myCustomStore );\n * const onClick = useCallback( () => {\n * const discountPercent = stockNumber > 50 ? 10: 20;\n * startSale( discountPercent );\n * }, [ stockNumber ] );\n * return <Button onClick={ onClick }>{ children }</Button>\n * }\n *\n * // Rendered somewhere in the application:\n * //\n * // <SaleButton>Start Sale!</SaleButton>\n * ```\n * @return {UseDispatchReturn<StoreNameOrDescriptor>} A custom react hook.\n */\nconst useDispatch = ( storeNameOrDescriptor ) => {\n\tconst { dispatch } = useRegistry();\n\treturn storeNameOrDescriptor === void 0\n\t\t? dispatch\n\t\t: dispatch( storeNameOrDescriptor );\n};\n\nexport default useDispatch;\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAW,MAAM,mCAAmC;;AAE3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAKC,qBAAqB,IAAM;EAChD,MAAM;IAAEC;EAAS,CAAC,GAAGH,WAAW,CAAC,CAAC;EAClC,OAAOE,qBAAqB,KAAK,KAAK,CAAC,GACpCC,QAAQ,GACRA,QAAQ,CAAED,qBAAsB,CAAC;AACrC,CAAC;AAED,eAAeD,WAAW"}
|