@wordpress/data
Advanced tools
Comparing version
@@ -8,3 +8,3 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
import { useLayoutEffect, useRef, useMemo, useCallback, useEffect, useReducer } from '@wordpress/element'; | ||
import { isShallowEqualObjects } from '@wordpress/is-shallow-equal'; | ||
import isShallowEqual from '@wordpress/is-shallow-equal'; | ||
/** | ||
@@ -129,3 +129,3 @@ * Internal dependencies | ||
if (isShallowEqualObjects(latestMapOutput.current, newMapOutput)) { | ||
if (isShallowEqual(latestMapOutput.current, newMapOutput)) { | ||
return; | ||
@@ -132,0 +132,0 @@ } |
/** | ||
* Internal dependencies | ||
*/ | ||
import defaultRegistry from './default-registry'; | ||
/** | ||
* @typedef {import('./registry').WPDataRegistry} WPDataRegistry | ||
*/ | ||
/** | ||
* Mark a selector as a registry selector. | ||
* | ||
* @param {function} registrySelector Function receiving a registry object and returning a state selector. | ||
* @param {Function} registrySelector Function receiving a registry object and returning a state selector. | ||
* | ||
* @return {function} marked registry selector. | ||
* @return {Function} marked registry selector. | ||
*/ | ||
export function createRegistrySelector(registrySelector) { | ||
registrySelector.isRegistrySelector = true; | ||
return registrySelector; | ||
var selector = function selector() { | ||
return registrySelector(selector.registry.select).apply(void 0, arguments); | ||
}; | ||
/** | ||
* Flag indicating to selector registration mapping that the selector should | ||
* be mapped as a registry selector. | ||
* | ||
* @type {boolean} | ||
*/ | ||
selector.isRegistrySelector = true; | ||
/** | ||
* Registry on which to call `select`, stubbed for non-standard usage to | ||
* use the default registry. | ||
* | ||
* @type {WPDataRegistry} | ||
*/ | ||
selector.registry = defaultRegistry; | ||
return selector; | ||
} | ||
@@ -15,5 +43,5 @@ /** | ||
* | ||
* @param {function} registryControl Function receiving a registry object and returning a control. | ||
* @param {Function} registryControl Function receiving a registry object and returning a control. | ||
* | ||
* @return {function} marked registry control. | ||
* @return {Function} marked registry control. | ||
*/ | ||
@@ -20,0 +48,0 @@ |
@@ -128,7 +128,7 @@ /** | ||
/** | ||
* Registers a generic store. | ||
* | ||
* @param {string} key Store registry key. | ||
* @param {Object} config Configuration (getSelectors, getActions, subscribe). | ||
*/ | ||
* Registers a generic store. | ||
* | ||
* @param {string} key Store registry key. | ||
* @param {Object} config Configuration (getSelectors, getActions, subscribe). | ||
*/ | ||
@@ -135,0 +135,0 @@ export var registerGenericStore = defaultRegistry.registerGenericStore; |
@@ -56,19 +56,8 @@ import _regeneratorRuntime from "@babel/runtime/regenerator"; | ||
if (selector.isRegistrySelector) { | ||
var mappedSelector = function mappedSelector(reg) { | ||
return function (state) { | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
return selector(reg).apply(void 0, [state.root].concat(args)); | ||
}; | ||
}; | ||
mappedSelector.isRegistrySelector = selector.isRegistrySelector; | ||
return mappedSelector; | ||
selector.registry = registry; | ||
} | ||
return function (state) { | ||
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
args[_key3 - 1] = arguments[_key3]; | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
@@ -78,3 +67,3 @@ | ||
}; | ||
})), store, registry); | ||
})), store); | ||
@@ -178,8 +167,6 @@ if (options.resolvers) { | ||
* | ||
* @param {Object} selectors Selectors to register. Keys will be used as | ||
* the public facing API. Selectors will get | ||
* passed the state as first argument. | ||
* @param {Object} store The store to which the selectors should be | ||
* mapped. | ||
* @param {WPDataRegistry} registry Registry reference. | ||
* @param {Object} selectors Selectors to register. Keys will be used as the | ||
* public facing API. Selectors will get passed the | ||
* state as first argument. | ||
* @param {Object} store The store to which the selectors should be mapped. | ||
* | ||
@@ -190,6 +177,4 @@ * @return {Object} Selectors mapped to the provided store. | ||
function mapSelectors(selectors, store, registry) { | ||
var createStateSelector = function createStateSelector(registeredSelector) { | ||
var registrySelector = registeredSelector.isRegistrySelector ? registeredSelector(registry.select) : registeredSelector; | ||
function mapSelectors(selectors, store) { | ||
var createStateSelector = function createStateSelector(registrySelector) { | ||
var selector = function runSelector() { | ||
@@ -268,4 +253,4 @@ // This function is an optimized implementation of: | ||
var selectorResolver = function selectorResolver() { | ||
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
@@ -356,5 +341,5 @@ | ||
var resolver, | ||
_len5, | ||
_len4, | ||
args, | ||
_key5, | ||
_key4, | ||
action, | ||
@@ -377,4 +362,4 @@ _args2 = arguments; | ||
case 3: | ||
for (_len5 = _args2.length, args = new Array(_len5 > 3 ? _len5 - 3 : 0), _key5 = 3; _key5 < _len5; _key5++) { | ||
args[_key5 - 3] = _args2[_key5]; | ||
for (_len4 = _args2.length, args = new Array(_len4 > 3 ? _len4 - 3 : 0), _key4 = 3; _key4 < _len4; _key4++) { | ||
args[_key4 - 3] = _args2[_key4]; | ||
} | ||
@@ -381,0 +366,0 @@ |
@@ -20,3 +20,3 @@ /** | ||
* | ||
* @returns {Object} Next state. | ||
* @return {Object} Next state. | ||
*/ | ||
@@ -23,0 +23,0 @@ |
@@ -15,3 +15,3 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
/** | ||
* Persistence plugin options. | ||
* @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options. | ||
* | ||
@@ -23,3 +23,2 @@ * @property {Storage} storage Persistent storage implementation. This must | ||
* | ||
* @typedef {WPDataPersistencePluginOptions} | ||
*/ | ||
@@ -26,0 +25,0 @@ |
@@ -8,3 +8,3 @@ /** | ||
* | ||
* @return {function} middleware. | ||
* @return {Function} middleware. | ||
*/ | ||
@@ -11,0 +11,0 @@ |
@@ -15,6 +15,4 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; | ||
/** | ||
* An isolated orchestrator of store registrations. | ||
* @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations. | ||
* | ||
* @typedef {Object} WPDataRegistry | ||
* | ||
* @property {Function} registerGenericStore Given a namespace key and settings | ||
@@ -38,5 +36,3 @@ * object, registers a new generic | ||
/** | ||
* An object of registry function overrides. | ||
* | ||
* @typedef {WPDataPlugin} | ||
* @typedef {Object} WPDataPlugin An object of registry function overrides. | ||
*/ | ||
@@ -43,0 +39,0 @@ |
@@ -16,3 +16,3 @@ "use strict"; | ||
var _isShallowEqual = require("@wordpress/is-shallow-equal"); | ||
var _isShallowEqual = _interopRequireDefault(require("@wordpress/is-shallow-equal")); | ||
@@ -143,3 +143,3 @@ var _useRegistry = _interopRequireDefault(require("../registry-provider/use-registry")); | ||
if ((0, _isShallowEqual.isShallowEqualObjects)(latestMapOutput.current, newMapOutput)) { | ||
if ((0, _isShallowEqual.default)(latestMapOutput.current, newMapOutput)) { | ||
return; | ||
@@ -146,0 +146,0 @@ } |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -9,12 +11,41 @@ value: true | ||
var _defaultRegistry = _interopRequireDefault(require("./default-registry")); | ||
/** | ||
* Internal dependencies | ||
*/ | ||
/** | ||
* @typedef {import('./registry').WPDataRegistry} WPDataRegistry | ||
*/ | ||
/** | ||
* Mark a selector as a registry selector. | ||
* | ||
* @param {function} registrySelector Function receiving a registry object and returning a state selector. | ||
* @param {Function} registrySelector Function receiving a registry object and returning a state selector. | ||
* | ||
* @return {function} marked registry selector. | ||
* @return {Function} marked registry selector. | ||
*/ | ||
function createRegistrySelector(registrySelector) { | ||
registrySelector.isRegistrySelector = true; | ||
return registrySelector; | ||
var selector = function selector() { | ||
return registrySelector(selector.registry.select).apply(void 0, arguments); | ||
}; | ||
/** | ||
* Flag indicating to selector registration mapping that the selector should | ||
* be mapped as a registry selector. | ||
* | ||
* @type {boolean} | ||
*/ | ||
selector.isRegistrySelector = true; | ||
/** | ||
* Registry on which to call `select`, stubbed for non-standard usage to | ||
* use the default registry. | ||
* | ||
* @type {WPDataRegistry} | ||
*/ | ||
selector.registry = _defaultRegistry.default; | ||
return selector; | ||
} | ||
@@ -24,5 +55,5 @@ /** | ||
* | ||
* @param {function} registryControl Function receiving a registry object and returning a control. | ||
* @param {Function} registryControl Function receiving a registry object and returning a control. | ||
* | ||
* @return {function} marked registry control. | ||
* @return {Function} marked registry control. | ||
*/ | ||
@@ -29,0 +60,0 @@ |
@@ -231,7 +231,7 @@ "use strict"; | ||
/** | ||
* Registers a generic store. | ||
* | ||
* @param {string} key Store registry key. | ||
* @param {Object} config Configuration (getSelectors, getActions, subscribe). | ||
*/ | ||
* Registers a generic store. | ||
* | ||
* @param {string} key Store registry key. | ||
* @param {Object} config Configuration (getSelectors, getActions, subscribe). | ||
*/ | ||
@@ -238,0 +238,0 @@ exports.subscribe = subscribe; |
@@ -78,19 +78,8 @@ "use strict"; | ||
if (selector.isRegistrySelector) { | ||
var mappedSelector = function mappedSelector(reg) { | ||
return function (state) { | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
return selector(reg).apply(void 0, [state.root].concat(args)); | ||
}; | ||
}; | ||
mappedSelector.isRegistrySelector = selector.isRegistrySelector; | ||
return mappedSelector; | ||
selector.registry = registry; | ||
} | ||
return function (state) { | ||
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
args[_key3 - 1] = arguments[_key3]; | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
@@ -100,3 +89,3 @@ | ||
}; | ||
})), store, registry); | ||
})), store); | ||
@@ -201,8 +190,6 @@ if (options.resolvers) { | ||
* | ||
* @param {Object} selectors Selectors to register. Keys will be used as | ||
* the public facing API. Selectors will get | ||
* passed the state as first argument. | ||
* @param {Object} store The store to which the selectors should be | ||
* mapped. | ||
* @param {WPDataRegistry} registry Registry reference. | ||
* @param {Object} selectors Selectors to register. Keys will be used as the | ||
* public facing API. Selectors will get passed the | ||
* state as first argument. | ||
* @param {Object} store The store to which the selectors should be mapped. | ||
* | ||
@@ -213,6 +200,4 @@ * @return {Object} Selectors mapped to the provided store. | ||
function mapSelectors(selectors, store, registry) { | ||
var createStateSelector = function createStateSelector(registeredSelector) { | ||
var registrySelector = registeredSelector.isRegistrySelector ? registeredSelector(registry.select) : registeredSelector; | ||
function mapSelectors(selectors, store) { | ||
var createStateSelector = function createStateSelector(registrySelector) { | ||
var selector = function runSelector() { | ||
@@ -291,4 +276,4 @@ // This function is an optimized implementation of: | ||
var selectorResolver = function selectorResolver() { | ||
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) { | ||
args[_key4] = arguments[_key4]; | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
@@ -379,5 +364,5 @@ | ||
var resolver, | ||
_len5, | ||
_len4, | ||
args, | ||
_key5, | ||
_key4, | ||
action, | ||
@@ -400,4 +385,4 @@ _args2 = arguments; | ||
case 3: | ||
for (_len5 = _args2.length, args = new Array(_len5 > 3 ? _len5 - 3 : 0), _key5 = 3; _key5 < _len5; _key5++) { | ||
args[_key5 - 3] = _args2[_key5]; | ||
for (_len4 = _args2.length, args = new Array(_len4 > 3 ? _len4 - 3 : 0), _key4 = 3; _key4 < _len4; _key4++) { | ||
args[_key4 - 3] = _args2[_key4]; | ||
} | ||
@@ -404,0 +389,0 @@ |
@@ -33,3 +33,3 @@ "use strict"; | ||
* | ||
* @returns {Object} Next state. | ||
* @return {Object} Next state. | ||
*/ | ||
@@ -36,0 +36,0 @@ var subKeysIsResolved = (0, _lodash.flowRight)([(0, _utils.onSubKey)('selectorName')])(function () { |
@@ -30,3 +30,3 @@ "use strict"; | ||
/** | ||
* Persistence plugin options. | ||
* @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options. | ||
* | ||
@@ -38,3 +38,2 @@ * @property {Storage} storage Persistent storage implementation. This must | ||
* | ||
* @typedef {WPDataPersistencePluginOptions} | ||
*/ | ||
@@ -41,0 +40,0 @@ |
@@ -19,3 +19,3 @@ "use strict"; | ||
* | ||
* @return {function} middleware. | ||
* @return {Function} middleware. | ||
*/ | ||
@@ -22,0 +22,0 @@ var promiseMiddleware = function promiseMiddleware() { |
@@ -29,6 +29,4 @@ "use strict"; | ||
/** | ||
* An isolated orchestrator of store registrations. | ||
* @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations. | ||
* | ||
* @typedef {Object} WPDataRegistry | ||
* | ||
* @property {Function} registerGenericStore Given a namespace key and settings | ||
@@ -52,5 +50,3 @@ * object, registers a new generic | ||
/** | ||
* An object of registry function overrides. | ||
* | ||
* @typedef {WPDataPlugin} | ||
* @typedef {Object} WPDataPlugin An object of registry function overrides. | ||
*/ | ||
@@ -57,0 +53,0 @@ |
{ | ||
"name": "@wordpress/data", | ||
"version": "4.7.0", | ||
"version": "4.8.0", | ||
"description": "Data module for WordPress.", | ||
@@ -26,8 +26,8 @@ "author": "The WordPress Contributors", | ||
"@babel/runtime": "^7.4.4", | ||
"@wordpress/compose": "^3.5.0", | ||
"@wordpress/deprecated": "^2.5.0", | ||
"@wordpress/element": "^2.6.0", | ||
"@wordpress/is-shallow-equal": "^1.5.0", | ||
"@wordpress/compose": "^3.6.0", | ||
"@wordpress/deprecated": "^2.6.0", | ||
"@wordpress/element": "^2.7.0", | ||
"@wordpress/is-shallow-equal": "^1.6.0", | ||
"@wordpress/priority-queue": "^1.3.0", | ||
"@wordpress/redux-routine": "^3.5.0", | ||
"@wordpress/redux-routine": "^3.6.0", | ||
"equivalent-key-map": "^0.2.2", | ||
@@ -42,3 +42,3 @@ "is-promise": "^2.1.0", | ||
}, | ||
"gitHead": "2080b50d4a41c9f746485519d1dc368dd9d9354d" | ||
"gitHead": "989502eccaadee1ea7666d6d9fb9f4d08b274546" | ||
} |
@@ -315,7 +315,7 @@ # Data | ||
- _registryControl_ `function`: Function receiving a registry object and returning a control. | ||
- _registryControl_ `Function`: Function receiving a registry object and returning a control. | ||
_Returns_ | ||
- `function`: marked registry control. | ||
- `Function`: marked registry control. | ||
@@ -328,7 +328,7 @@ <a name="createRegistrySelector" href="#createRegistrySelector">#</a> **createRegistrySelector** | ||
- _registrySelector_ `function`: Function receiving a registry object and returning a state selector. | ||
- _registrySelector_ `Function`: Function receiving a registry object and returning a state selector. | ||
_Returns_ | ||
- `function`: marked registry selector. | ||
- `Function`: marked registry selector. | ||
@@ -335,0 +335,0 @@ <a name="dispatch" href="#dispatch">#</a> **dispatch** |
@@ -13,3 +13,3 @@ /** | ||
} from '@wordpress/element'; | ||
import { isShallowEqualObjects } from '@wordpress/is-shallow-equal'; | ||
import isShallowEqual from '@wordpress/is-shallow-equal'; | ||
@@ -94,6 +94,3 @@ /** | ||
try { | ||
if ( | ||
latestMapSelect.current !== mapSelect || | ||
latestMapOutputError.current | ||
) { | ||
if ( latestMapSelect.current !== mapSelect || latestMapOutputError.current ) { | ||
mapOutput = mapSelect( registry.select, registry ); | ||
@@ -104,3 +101,5 @@ } else { | ||
} catch ( error ) { | ||
let errorMessage = `An error occurred while running 'mapSelect': ${ error.message }`; | ||
let errorMessage = `An error occurred while running 'mapSelect': ${ | ||
error.message | ||
}`; | ||
@@ -135,3 +134,3 @@ if ( latestMapOutputError.current ) { | ||
); | ||
if ( isShallowEqualObjects( latestMapOutput.current, newMapOutput ) ) { | ||
if ( isShallowEqual( latestMapOutput.current, newMapOutput ) ) { | ||
return; | ||
@@ -138,0 +137,0 @@ } |
@@ -135,3 +135,89 @@ /** | ||
} ); | ||
describe( 'rerenders as expected with various mapSelect return types', () => { | ||
const getComponent = ( mapSelectSpy ) => () => { | ||
const data = useSelect( mapSelectSpy, [] ); | ||
return <div data={ data } />; | ||
}; | ||
let subscribedSpy, TestComponent; | ||
const mapSelectSpy = jest.fn( | ||
( select ) => select( 'testStore' ).testSelector() | ||
); | ||
const selectorSpy = jest.fn(); | ||
const subscribeCallback = ( subscription ) => { | ||
subscribedSpy = subscription; | ||
}; | ||
beforeEach( () => { | ||
registry.registerStore( 'testStore', { | ||
reducer: () => null, | ||
selectors: { | ||
testSelector: selectorSpy, | ||
}, | ||
} ); | ||
registry.subscribe = subscribeCallback; | ||
TestComponent = getComponent( mapSelectSpy ); | ||
} ); | ||
afterEach( () => { | ||
selectorSpy.mockClear(); | ||
mapSelectSpy.mockClear(); | ||
} ); | ||
it.each( [ | ||
[ | ||
'boolean', | ||
[ false, true ], | ||
], | ||
[ | ||
'number', | ||
[ 10, 20 ], | ||
], | ||
[ | ||
'string', | ||
[ 'bar', 'cheese' ], | ||
], | ||
[ | ||
'array', | ||
[ [ 10, 20 ], [ 10, 30 ] ], | ||
], | ||
[ | ||
'object', | ||
[ { foo: 'bar' }, { foo: 'cheese' } ], | ||
], | ||
[ | ||
'null', | ||
[ null, undefined ], | ||
], | ||
[ | ||
'undefined', | ||
[ undefined, 42 ], | ||
], | ||
] )( 'renders as expected with %s return values', ( | ||
type, | ||
testValues, | ||
) => { | ||
const [ valueA, valueB ] = testValues; | ||
selectorSpy.mockReturnValue( valueA ); | ||
let renderer; | ||
act( () => { | ||
renderer = TestRenderer.create( | ||
<RegistryProvider value={ registry }> | ||
<TestComponent /> | ||
</RegistryProvider> | ||
); | ||
} ); | ||
const testInstance = renderer.root; | ||
// ensure expected state was rendered. | ||
expect( testInstance.findByType( 'div' ).props.data ).toEqual( valueA ); | ||
// Update the returned value from the selector and trigger the | ||
// subscription which should in turn trigger a re-render. | ||
act( () => { | ||
selectorSpy.mockReturnValue( valueB ); | ||
subscribedSpy(); | ||
} ); | ||
expect( testInstance.findByType( 'div' ).props.data ).toEqual( valueB ); | ||
expect( mapSelectSpy ).toHaveBeenCalledTimes( 3 ); | ||
} ); | ||
} ); | ||
} ); | ||
@@ -38,3 +38,3 @@ /** | ||
const actionReturnedFromDispatch = Promise.resolve( _dispatch( 'counter' ).increment( count ) ); | ||
expect( actionReturnedFromDispatch ).resolves.toEqual( | ||
return expect( actionReturnedFromDispatch ).resolves.toEqual( | ||
{ | ||
@@ -170,3 +170,3 @@ type: 'increment', | ||
); | ||
expect( actionReturnedFromDispatch ).resolves.toEqual( { | ||
return expect( actionReturnedFromDispatch ).resolves.toEqual( { | ||
type: 'update', | ||
@@ -173,0 +173,0 @@ count: innerCount + 1, |
/** | ||
* Internal dependencies | ||
*/ | ||
import defaultRegistry from './default-registry'; | ||
/** | ||
* @typedef {import('./registry').WPDataRegistry} WPDataRegistry | ||
*/ | ||
/** | ||
* Mark a selector as a registry selector. | ||
* | ||
* @param {function} registrySelector Function receiving a registry object and returning a state selector. | ||
* @param {Function} registrySelector Function receiving a registry object and returning a state selector. | ||
* | ||
* @return {function} marked registry selector. | ||
* @return {Function} marked registry selector. | ||
*/ | ||
export function createRegistrySelector( registrySelector ) { | ||
registrySelector.isRegistrySelector = true; | ||
const selector = ( ...args ) => registrySelector( selector.registry.select )( ...args ); | ||
return registrySelector; | ||
/** | ||
* Flag indicating to selector registration mapping that the selector should | ||
* be mapped as a registry selector. | ||
* | ||
* @type {boolean} | ||
*/ | ||
selector.isRegistrySelector = true; | ||
/** | ||
* Registry on which to call `select`, stubbed for non-standard usage to | ||
* use the default registry. | ||
* | ||
* @type {WPDataRegistry} | ||
*/ | ||
selector.registry = defaultRegistry; | ||
return selector; | ||
} | ||
@@ -17,5 +42,5 @@ | ||
* | ||
* @param {function} registryControl Function receiving a registry object and returning a control. | ||
* @param {Function} registryControl Function receiving a registry object and returning a control. | ||
* | ||
* @return {function} marked registry control. | ||
* @return {Function} marked registry control. | ||
*/ | ||
@@ -22,0 +47,0 @@ export function createRegistryControl( registryControl ) { |
@@ -136,7 +136,7 @@ /** | ||
/** | ||
* Registers a generic store. | ||
* | ||
* @param {string} key Store registry key. | ||
* @param {Object} config Configuration (getSelectors, getActions, subscribe). | ||
*/ | ||
* Registers a generic store. | ||
* | ||
* @param {string} key Store registry key. | ||
* @param {Object} config Configuration (getSelectors, getActions, subscribe). | ||
*/ | ||
export const registerGenericStore = defaultRegistry.registerGenericStore; | ||
@@ -143,0 +143,0 @@ |
@@ -54,7 +54,3 @@ /** | ||
if ( selector.isRegistrySelector ) { | ||
const mappedSelector = ( reg ) => ( state, ...args ) => { | ||
return selector( reg )( state.root, ...args ); | ||
}; | ||
mappedSelector.isRegistrySelector = selector.isRegistrySelector; | ||
return mappedSelector; | ||
selector.registry = registry; | ||
} | ||
@@ -64,3 +60,3 @@ | ||
} ), | ||
}, store, registry ); | ||
}, store ); | ||
if ( options.resolvers ) { | ||
@@ -157,17 +153,11 @@ const result = mapResolvers( options.resolvers, selectors, store ); | ||
* | ||
* @param {Object} selectors Selectors to register. Keys will be used as | ||
* the public facing API. Selectors will get | ||
* passed the state as first argument. | ||
* @param {Object} store The store to which the selectors should be | ||
* mapped. | ||
* @param {WPDataRegistry} registry Registry reference. | ||
* @param {Object} selectors Selectors to register. Keys will be used as the | ||
* public facing API. Selectors will get passed the | ||
* state as first argument. | ||
* @param {Object} store The store to which the selectors should be mapped. | ||
* | ||
* @return {Object} Selectors mapped to the provided store. | ||
*/ | ||
function mapSelectors( selectors, store, registry ) { | ||
const createStateSelector = ( registeredSelector ) => { | ||
const registrySelector = registeredSelector.isRegistrySelector ? | ||
registeredSelector( registry.select ) : | ||
registeredSelector; | ||
function mapSelectors( selectors, store ) { | ||
const createStateSelector = ( registrySelector ) => { | ||
const selector = function runSelector() { | ||
@@ -174,0 +164,0 @@ // This function is an optimized implementation of: |
@@ -21,3 +21,3 @@ /** | ||
* | ||
* @returns {Object} Next state. | ||
* @return {Object} Next state. | ||
*/ | ||
@@ -24,0 +24,0 @@ const subKeysIsResolved = flowRight( [ |
@@ -39,3 +39,3 @@ /** | ||
registry.dispatch( 'store2' ).action2(); | ||
expect( action1 ).toBeCalled(); | ||
expect( action1 ).toHaveBeenCalled(); | ||
} ); | ||
@@ -111,4 +111,3 @@ } ); | ||
} ); | ||
describe( 'various action types have expected response and resolve as ' + | ||
'expected with controls middleware', () => { | ||
describe( 'various action types have expected response and resolve as expected with controls middleware', () => { | ||
const actions = { | ||
@@ -169,4 +168,3 @@ *withPromise() { | ||
} ); | ||
describe( 'action type resolves as expected with just promise ' + | ||
'middleware', () => { | ||
describe( 'action type resolves as expected with just promise middleware', () => { | ||
const actions = { | ||
@@ -173,0 +171,0 @@ normal: () => ( { type: 'NORMAL' } ), |
@@ -13,3 +13,3 @@ /** | ||
/** | ||
* Persistence plugin options. | ||
* @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options. | ||
* | ||
@@ -21,3 +21,2 @@ * @property {Storage} storage Persistent storage implementation. This must | ||
* | ||
* @typedef {WPDataPersistencePluginOptions} | ||
*/ | ||
@@ -24,0 +23,0 @@ |
@@ -9,3 +9,3 @@ /** | ||
* | ||
* @return {function} middleware. | ||
* @return {Function} middleware. | ||
*/ | ||
@@ -12,0 +12,0 @@ const promiseMiddleware = () => ( next ) => ( action ) => { |
@@ -16,6 +16,4 @@ /** | ||
/** | ||
* An isolated orchestrator of store registrations. | ||
* @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations. | ||
* | ||
* @typedef {Object} WPDataRegistry | ||
* | ||
* @property {Function} registerGenericStore Given a namespace key and settings | ||
@@ -39,5 +37,3 @@ * object, registers a new generic | ||
/** | ||
* An object of registry function overrides. | ||
* | ||
* @typedef {WPDataPlugin} | ||
* @typedef {Object} WPDataPlugin An object of registry function overrides. | ||
*/ | ||
@@ -44,0 +40,0 @@ |
@@ -441,6 +441,6 @@ /** | ||
expect( registry.select( 'reducer1' ).selector1() ).toEqual( 'result1' ); | ||
expect( selector1 ).toBeCalledWith( store.getState() ); | ||
expect( selector1 ).toHaveBeenCalledWith( store.getState() ); | ||
expect( registry.select( 'reducer1' ).selector2() ).toEqual( 'result2' ); | ||
expect( selector2 ).toBeCalledWith( store.getState() ); | ||
expect( selector2 ).toHaveBeenCalledWith( store.getState() ); | ||
} ); | ||
@@ -468,2 +468,34 @@ | ||
} ); | ||
it( 'should run the registry selector from a non-registry selector', () => { | ||
const selector1 = () => 'result1'; | ||
const selector2 = createRegistrySelector( ( select ) => () => | ||
select( 'reducer1' ).selector1() | ||
); | ||
const selector3 = () => selector2(); | ||
registry.registerStore( 'reducer1', { | ||
reducer: () => 'state1', | ||
selectors: { | ||
selector1, | ||
}, | ||
} ); | ||
registry.registerStore( 'reducer2', { | ||
reducer: () => 'state1', | ||
selectors: { | ||
selector2, | ||
selector3, | ||
}, | ||
} ); | ||
expect( registry.select( 'reducer2' ).selector3() ).toEqual( 'result1' ); | ||
} ); | ||
it( 'gracefully stubs select on selector calls', () => { | ||
const selector = createRegistrySelector( ( select ) => () => select ); | ||
const maybeSelect = selector(); | ||
expect( maybeSelect ).toEqual( expect.any( Function ) ); | ||
expect( maybeSelect() ).toEqual( expect.any( Object ) ); | ||
} ); | ||
} ); | ||
@@ -470,0 +502,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
521798
0.53%8260
1.56%