@wordpress/core-data 4.0.1 → 4.0.5
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/README.md +13 -7
- package/build/actions.js +178 -122
- package/build/actions.js.map +1 -1
- package/build/batch/default-processor.js +58 -27
- package/build/batch/default-processor.js.map +1 -1
- package/build/entities.js +70 -23
- package/build/entities.js.map +1 -1
- package/build/fetch/__experimental-fetch-url-data.js +1 -1
- package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build/index.js +9 -17
- package/build/index.js.map +1 -1
- package/build/locks/actions.js +17 -77
- package/build/locks/actions.js.map +1 -1
- package/build/locks/engine.js +77 -0
- package/build/locks/engine.js.map +1 -0
- package/build/locks/reducer.js +1 -5
- package/build/locks/reducer.js.map +1 -1
- package/build/locks/selectors.js +6 -6
- package/build/locks/selectors.js.map +1 -1
- package/build/queried-data/get-query-parts.js +9 -4
- package/build/queried-data/get-query-parts.js.map +1 -1
- package/build/queried-data/selectors.js +3 -9
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +17 -22
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +151 -97
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +79 -14
- package/build/selectors.js.map +1 -1
- package/build/utils/forward-resolver.js +23 -0
- package/build/utils/forward-resolver.js.map +1 -0
- package/build/utils/index.js +11 -3
- package/build/utils/index.js.map +1 -1
- package/build/utils/is-raw-attribute.js +19 -0
- package/build/utils/is-raw-attribute.js.map +1 -0
- package/build-module/actions.js +155 -112
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/default-processor.js +57 -27
- package/build-module/batch/default-processor.js.map +1 -1
- package/build-module/entities.js +65 -19
- package/build-module/entities.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +1 -1
- package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build-module/index.js +10 -14
- package/build-module/index.js.map +1 -1
- package/build-module/locks/actions.js +14 -68
- package/build-module/locks/actions.js.map +1 -1
- package/build-module/locks/engine.js +66 -0
- package/build-module/locks/engine.js.map +1 -0
- package/build-module/locks/reducer.js +1 -2
- package/build-module/locks/reducer.js.map +1 -1
- package/build-module/locks/selectors.js +4 -4
- package/build-module/locks/selectors.js.map +1 -1
- package/build-module/queried-data/get-query-parts.js +9 -4
- package/build-module/queried-data/get-query-parts.js.map +1 -1
- package/build-module/queried-data/selectors.js +3 -9
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +15 -19
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +123 -81
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +74 -13
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/forward-resolver.js +15 -0
- package/build-module/utils/forward-resolver.js.map +1 -0
- package/build-module/utils/index.js +2 -1
- package/build-module/utils/index.js.map +1 -1
- package/build-module/utils/is-raw-attribute.js +12 -0
- package/build-module/utils/is-raw-attribute.js.map +1 -0
- package/package.json +10 -11
- package/src/actions.js +163 -194
- package/src/batch/default-processor.js +57 -26
- package/src/batch/test/default-processor.js +53 -26
- package/src/entities.js +47 -19
- package/src/fetch/__experimental-fetch-url-data.js +1 -1
- package/src/index.js +7 -10
- package/src/locks/actions.js +10 -61
- package/src/locks/engine.js +43 -0
- package/src/locks/reducer.js +1 -3
- package/src/locks/selectors.js +4 -4
- package/src/locks/test/engine.js +135 -0
- package/src/locks/test/reducer.js +1 -1
- package/src/locks/test/selectors.js +105 -124
- package/src/queried-data/get-query-parts.js +11 -6
- package/src/queried-data/selectors.js +2 -9
- package/src/queried-data/test/get-query-parts.js +1 -1
- package/src/queried-data/test/selectors.js +1 -0
- package/src/reducer.js +14 -19
- package/src/resolvers.js +132 -120
- package/src/selectors.js +156 -44
- package/src/test/actions.js +330 -170
- package/src/test/entities.js +40 -26
- package/src/test/resolvers.js +270 -223
- package/src/test/selectors.js +127 -1
- package/src/utils/forward-resolver.js +14 -0
- package/src/utils/index.js +2 -1
- package/src/utils/is-raw-attribute.js +11 -0
- package/src/utils/test/is-raw-attribute.js +22 -0
- package/build/controls.js +0 -44
- package/build/controls.js.map +0 -1
- package/build/locks/index.js +0 -47
- package/build/locks/index.js.map +0 -1
- package/build/utils/if-not-resolved.js +0 -46
- package/build/utils/if-not-resolved.js.map +0 -1
- package/build-module/controls.js +0 -31
- package/build-module/controls.js.map +0 -1
- package/build-module/locks/index.js +0 -4
- package/build-module/locks/index.js.map +0 -1
- package/build-module/utils/if-not-resolved.js +0 -36
- package/build-module/utils/if-not-resolved.js.map +0 -1
- package/src/controls.js +0 -31
- package/src/locks/index.js +0 -3
- package/src/locks/test/actions.js +0 -307
- package/src/test/integration.js +0 -264
- package/src/utils/if-not-resolved.js +0 -40
- package/src/utils/test/if-not-resolved.js +0 -75
package/src/test/selectors.js
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
__experimentalGetEntityRecordNoResolver,
|
|
12
12
|
hasEntityRecords,
|
|
13
13
|
getEntityRecords,
|
|
14
|
+
getRawEntityRecord,
|
|
14
15
|
__experimentalGetDirtyEntityRecords,
|
|
15
16
|
__experimentalGetEntitiesBeingSaved,
|
|
16
17
|
getEntityRecordNonTransientEdits,
|
|
@@ -204,6 +205,76 @@ describe( 'hasEntityRecords', () => {
|
|
|
204
205
|
} );
|
|
205
206
|
} );
|
|
206
207
|
|
|
208
|
+
describe( 'getRawEntityRecord', () => {
|
|
209
|
+
const data = {
|
|
210
|
+
someKind: {
|
|
211
|
+
someName: {
|
|
212
|
+
queriedData: {
|
|
213
|
+
items: {
|
|
214
|
+
default: {
|
|
215
|
+
post: {
|
|
216
|
+
title: {
|
|
217
|
+
raw: { html: '<h1>post</h1>' },
|
|
218
|
+
rendered:
|
|
219
|
+
'<div id="post"><h1>rendered post</h1></div>',
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
},
|
|
224
|
+
itemIsComplete: {
|
|
225
|
+
default: {
|
|
226
|
+
post: true,
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
queries: {},
|
|
230
|
+
},
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
};
|
|
234
|
+
it( 'should preserve the structure of `raw` field by default', () => {
|
|
235
|
+
const state = deepFreeze( {
|
|
236
|
+
entities: {
|
|
237
|
+
config: [
|
|
238
|
+
{
|
|
239
|
+
kind: 'someKind',
|
|
240
|
+
name: 'someName',
|
|
241
|
+
},
|
|
242
|
+
],
|
|
243
|
+
data: { ...data },
|
|
244
|
+
},
|
|
245
|
+
} );
|
|
246
|
+
expect(
|
|
247
|
+
getRawEntityRecord( state, 'someKind', 'someName', 'post' )
|
|
248
|
+
).toEqual( {
|
|
249
|
+
title: {
|
|
250
|
+
raw: { html: '<h1>post</h1>' },
|
|
251
|
+
rendered: '<div id="post"><h1>rendered post</h1></div>',
|
|
252
|
+
},
|
|
253
|
+
} );
|
|
254
|
+
} );
|
|
255
|
+
it( 'should flatten the structure of `raw` field for entities configured with rawAttributes', () => {
|
|
256
|
+
const state = deepFreeze( {
|
|
257
|
+
entities: {
|
|
258
|
+
config: [
|
|
259
|
+
{
|
|
260
|
+
kind: 'someKind',
|
|
261
|
+
name: 'someName',
|
|
262
|
+
rawAttributes: [ 'title' ],
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
data: { ...data },
|
|
266
|
+
},
|
|
267
|
+
} );
|
|
268
|
+
expect(
|
|
269
|
+
getRawEntityRecord( state, 'someKind', 'someName', 'post' )
|
|
270
|
+
).toEqual( {
|
|
271
|
+
title: {
|
|
272
|
+
html: '<h1>post</h1>',
|
|
273
|
+
},
|
|
274
|
+
} );
|
|
275
|
+
} );
|
|
276
|
+
} );
|
|
277
|
+
|
|
207
278
|
describe( 'getEntityRecords', () => {
|
|
208
279
|
it( 'should return null by default', () => {
|
|
209
280
|
const state = deepFreeze( {
|
|
@@ -347,7 +418,56 @@ describe( 'getEntityRecords', () => {
|
|
|
347
418
|
} );
|
|
348
419
|
|
|
349
420
|
describe( '__experimentalGetDirtyEntityRecords', () => {
|
|
350
|
-
it( '
|
|
421
|
+
it( 'returns a map of objects with each raw edited entity record and its corresponding edits', () => {
|
|
422
|
+
const state = deepFreeze( {
|
|
423
|
+
entities: {
|
|
424
|
+
config: [
|
|
425
|
+
{
|
|
426
|
+
kind: 'someKind',
|
|
427
|
+
name: 'someName',
|
|
428
|
+
transientEdits: { someTransientEditProperty: true },
|
|
429
|
+
},
|
|
430
|
+
],
|
|
431
|
+
data: {
|
|
432
|
+
someKind: {
|
|
433
|
+
someName: {
|
|
434
|
+
queriedData: {
|
|
435
|
+
items: {
|
|
436
|
+
default: {
|
|
437
|
+
someKey: {
|
|
438
|
+
someProperty: 'somePersistedValue',
|
|
439
|
+
someRawProperty: {
|
|
440
|
+
raw: 'somePersistedRawValue',
|
|
441
|
+
},
|
|
442
|
+
id: 'someKey',
|
|
443
|
+
},
|
|
444
|
+
},
|
|
445
|
+
},
|
|
446
|
+
itemIsComplete: {
|
|
447
|
+
default: {
|
|
448
|
+
someKey: true,
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
edits: {
|
|
453
|
+
someKey: {
|
|
454
|
+
someProperty: 'someEditedValue',
|
|
455
|
+
someRawProperty: 'someEditedRawValue',
|
|
456
|
+
someTransientEditProperty:
|
|
457
|
+
'someEditedTransientEditValue',
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
},
|
|
461
|
+
},
|
|
462
|
+
},
|
|
463
|
+
},
|
|
464
|
+
} );
|
|
465
|
+
expect( __experimentalGetDirtyEntityRecords( state ) ).toEqual( [
|
|
466
|
+
{ kind: 'someKind', name: 'someName', key: 'someKey', title: '' },
|
|
467
|
+
] );
|
|
468
|
+
} );
|
|
469
|
+
|
|
470
|
+
it( 'excludes entity records that no longer exist', () => {
|
|
351
471
|
const state = deepFreeze( {
|
|
352
472
|
entities: {
|
|
353
473
|
config: [
|
|
@@ -385,6 +505,12 @@ describe( '__experimentalGetDirtyEntityRecords', () => {
|
|
|
385
505
|
someTransientEditProperty:
|
|
386
506
|
'someEditedTransientEditValue',
|
|
387
507
|
},
|
|
508
|
+
deletedKey: {
|
|
509
|
+
someProperty: 'someEditedValue',
|
|
510
|
+
someRawProperty: 'someEditedRawValue',
|
|
511
|
+
someTransientEditProperty:
|
|
512
|
+
'someEditedTransientEditValue',
|
|
513
|
+
},
|
|
388
514
|
},
|
|
389
515
|
},
|
|
390
516
|
},
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Higher-order function which forward the resolution to another resolver with the same arguments.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} resolverName forwarded resolver.
|
|
5
|
+
*
|
|
6
|
+
* @return {Function} Enhanced resolver.
|
|
7
|
+
*/
|
|
8
|
+
const forwardResolver = ( resolverName ) => ( ...args ) => async ( {
|
|
9
|
+
resolveSelect,
|
|
10
|
+
} ) => {
|
|
11
|
+
await resolveSelect[ resolverName ]( ...args );
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export default forwardResolver;
|
package/src/utils/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { default as conservativeMapItem } from './conservative-map-item';
|
|
2
2
|
export { default as getNormalizedCommaSeparable } from './get-normalized-comma-separable';
|
|
3
3
|
export { default as ifMatchingAction } from './if-matching-action';
|
|
4
|
-
export { default as
|
|
4
|
+
export { default as forwardResolver } from './forward-resolver';
|
|
5
5
|
export { default as onSubKey } from './on-sub-key';
|
|
6
6
|
export { default as replaceAction } from './replace-action';
|
|
7
7
|
export { default as withWeakMapCache } from './with-weak-map-cache';
|
|
8
|
+
export { default as isRawAttribute } from './is-raw-attribute';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether the attribute is a "raw" attribute or not.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} entity Entity data.
|
|
5
|
+
* @param {string} attribute Attribute name.
|
|
6
|
+
*
|
|
7
|
+
* @return {boolean} Is the attribute raw
|
|
8
|
+
*/
|
|
9
|
+
export default function isRawAttribute( entity, attribute ) {
|
|
10
|
+
return ( entity.rawAttributes || [] ).includes( attribute );
|
|
11
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { isRawAttribute } from '../';
|
|
5
|
+
|
|
6
|
+
describe( 'isRawAttribute', () => {
|
|
7
|
+
it( 'should correctly assess that the attribute is not raw', () => {
|
|
8
|
+
const entity = {
|
|
9
|
+
kind: 'someKind',
|
|
10
|
+
name: 'someName',
|
|
11
|
+
};
|
|
12
|
+
expect( isRawAttribute( entity, 'title' ) ).toBe( false );
|
|
13
|
+
} );
|
|
14
|
+
it( 'should correctly assess that the attribute is raw', () => {
|
|
15
|
+
const entity = {
|
|
16
|
+
kind: 'someKind',
|
|
17
|
+
name: 'someName',
|
|
18
|
+
rawAttributes: [ 'title' ],
|
|
19
|
+
};
|
|
20
|
+
expect( isRawAttribute( entity, 'title' ) ).toBe( true );
|
|
21
|
+
} );
|
|
22
|
+
} );
|
package/build/controls.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.regularFetch = regularFetch;
|
|
7
|
-
exports.getDispatch = getDispatch;
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _data = require("@wordpress/data");
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* WordPress dependencies
|
|
14
|
-
*/
|
|
15
|
-
function regularFetch(url) {
|
|
16
|
-
return {
|
|
17
|
-
type: 'REGULAR_FETCH',
|
|
18
|
-
url
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function getDispatch() {
|
|
23
|
-
return {
|
|
24
|
-
type: 'GET_DISPATCH'
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const controls = {
|
|
29
|
-
async REGULAR_FETCH({
|
|
30
|
-
url
|
|
31
|
-
}) {
|
|
32
|
-
const {
|
|
33
|
-
data
|
|
34
|
-
} = await window.fetch(url).then(res => res.json());
|
|
35
|
-
return data;
|
|
36
|
-
},
|
|
37
|
-
|
|
38
|
-
GET_DISPATCH: (0, _data.createRegistryControl)(({
|
|
39
|
-
dispatch
|
|
40
|
-
}) => () => dispatch)
|
|
41
|
-
};
|
|
42
|
-
var _default = controls;
|
|
43
|
-
exports.default = _default;
|
|
44
|
-
//# sourceMappingURL=controls.js.map
|
package/build/controls.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/controls.js"],"names":["regularFetch","url","type","getDispatch","controls","REGULAR_FETCH","data","window","fetch","then","res","json","GET_DISPATCH","dispatch"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;AAGO,SAASA,YAAT,CAAuBC,GAAvB,EAA6B;AACnC,SAAO;AACNC,IAAAA,IAAI,EAAE,eADA;AAEND,IAAAA;AAFM,GAAP;AAIA;;AAEM,SAASE,WAAT,GAAuB;AAC7B,SAAO;AACND,IAAAA,IAAI,EAAE;AADA,GAAP;AAGA;;AAED,MAAME,QAAQ,GAAG;AAChB,QAAMC,aAAN,CAAqB;AAAEJ,IAAAA;AAAF,GAArB,EAA+B;AAC9B,UAAM;AAAEK,MAAAA;AAAF,QAAW,MAAMC,MAAM,CAC3BC,KADqB,CACdP,GADc,EAErBQ,IAFqB,CAEbC,GAAF,IAAWA,GAAG,CAACC,IAAJ,EAFI,CAAvB;AAIA,WAAOL,IAAP;AACA,GAPe;;AAShBM,EAAAA,YAAY,EAAE,iCAAuB,CAAE;AAAEC,IAAAA;AAAF,GAAF,KAAoB,MAAMA,QAAjD;AATE,CAAjB;eAYeT,Q","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createRegistryControl } from '@wordpress/data';\n\nexport function regularFetch( url ) {\n\treturn {\n\t\ttype: 'REGULAR_FETCH',\n\t\turl,\n\t};\n}\n\nexport function getDispatch() {\n\treturn {\n\t\ttype: 'GET_DISPATCH',\n\t};\n}\n\nconst controls = {\n\tasync REGULAR_FETCH( { url } ) {\n\t\tconst { data } = await window\n\t\t\t.fetch( url )\n\t\t\t.then( ( res ) => res.json() );\n\n\t\treturn data;\n\t},\n\n\tGET_DISPATCH: createRegistryControl( ( { dispatch } ) => () => dispatch ),\n};\n\nexport default controls;\n"]}
|
package/build/locks/index.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
var _exportNames = {
|
|
9
|
-
reducer: true
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "reducer", {
|
|
12
|
-
enumerable: true,
|
|
13
|
-
get: function () {
|
|
14
|
-
return _reducer.default;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
var _actions = require("./actions");
|
|
19
|
-
|
|
20
|
-
Object.keys(_actions).forEach(function (key) {
|
|
21
|
-
if (key === "default" || key === "__esModule") return;
|
|
22
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
23
|
-
if (key in exports && exports[key] === _actions[key]) return;
|
|
24
|
-
Object.defineProperty(exports, key, {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _actions[key];
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
var _selectors = require("./selectors");
|
|
33
|
-
|
|
34
|
-
Object.keys(_selectors).forEach(function (key) {
|
|
35
|
-
if (key === "default" || key === "__esModule") return;
|
|
36
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
37
|
-
if (key in exports && exports[key] === _selectors[key]) return;
|
|
38
|
-
Object.defineProperty(exports, key, {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
get: function () {
|
|
41
|
-
return _selectors[key];
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
var _reducer = _interopRequireDefault(require("./reducer"));
|
|
47
|
-
//# sourceMappingURL=index.js.map
|
package/build/locks/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/locks/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA","sourcesContent":["export * from './actions';\nexport * from './selectors';\nexport { default as reducer } from './reducer';\n"]}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _data = require("@wordpress/data");
|
|
9
|
-
|
|
10
|
-
var _name = require("../name");
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* WordPress dependencies
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Internal dependencies
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Higher-order function which invokes the given resolver only if it has not
|
|
22
|
-
* already been resolved with the arguments passed to the enhanced function.
|
|
23
|
-
*
|
|
24
|
-
* This only considers resolution state, and notably does not support resolver
|
|
25
|
-
* custom `isFulfilled` behavior.
|
|
26
|
-
*
|
|
27
|
-
* @param {Function} resolver Original resolver.
|
|
28
|
-
* @param {string} selectorName Selector name associated with resolver.
|
|
29
|
-
*
|
|
30
|
-
* @return {Function} Enhanced resolver.
|
|
31
|
-
*/
|
|
32
|
-
const ifNotResolved = (resolver, selectorName) =>
|
|
33
|
-
/**
|
|
34
|
-
* @param {...any} args Original resolver arguments.
|
|
35
|
-
*/
|
|
36
|
-
function* resolveIfNotResolved(...args) {
|
|
37
|
-
const hasStartedResolution = yield _data.controls.select(_name.STORE_NAME, 'hasStartedResolution', selectorName, args);
|
|
38
|
-
|
|
39
|
-
if (!hasStartedResolution) {
|
|
40
|
-
yield* resolver(...args);
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
var _default = ifNotResolved;
|
|
45
|
-
exports.default = _default;
|
|
46
|
-
//# sourceMappingURL=if-not-resolved.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/utils/if-not-resolved.js"],"names":["ifNotResolved","resolver","selectorName","resolveIfNotResolved","args","hasStartedResolution","controls","select","STORE_NAME"],"mappings":";;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,aAAa,GAAG,CAAEC,QAAF,EAAYC,YAAZ;AACrB;AACD;AACA;AACC,UAAUC,oBAAV,CAAgC,GAAGC,IAAnC,EAA0C;AACzC,QAAMC,oBAAoB,GAAG,MAAMC,eAASC,MAAT,CAClCC,gBADkC,EAElC,sBAFkC,EAGlCN,YAHkC,EAIlCE,IAJkC,CAAnC;;AAOA,MAAK,CAAEC,oBAAP,EAA8B;AAC7B,WAAOJ,QAAQ,CAAE,GAAGG,IAAL,CAAf;AACA;AACD,CAfF;;eAiBeJ,a","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { controls } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../name';\n\n/**\n * Higher-order function which invokes the given resolver only if it has not\n * already been resolved with the arguments passed to the enhanced function.\n *\n * This only considers resolution state, and notably does not support resolver\n * custom `isFulfilled` behavior.\n *\n * @param {Function} resolver Original resolver.\n * @param {string} selectorName Selector name associated with resolver.\n *\n * @return {Function} Enhanced resolver.\n */\nconst ifNotResolved = ( resolver, selectorName ) =>\n\t/**\n\t * @param {...any} args Original resolver arguments.\n\t */\n\tfunction* resolveIfNotResolved( ...args ) {\n\t\tconst hasStartedResolution = yield controls.select(\n\t\t\tSTORE_NAME,\n\t\t\t'hasStartedResolution',\n\t\t\tselectorName,\n\t\t\targs\n\t\t);\n\n\t\tif ( ! hasStartedResolution ) {\n\t\t\tyield* resolver( ...args );\n\t\t}\n\t};\n\nexport default ifNotResolved;\n"]}
|
package/build-module/controls.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { createRegistryControl } from '@wordpress/data';
|
|
5
|
-
export function regularFetch(url) {
|
|
6
|
-
return {
|
|
7
|
-
type: 'REGULAR_FETCH',
|
|
8
|
-
url
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
export function getDispatch() {
|
|
12
|
-
return {
|
|
13
|
-
type: 'GET_DISPATCH'
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
const controls = {
|
|
17
|
-
async REGULAR_FETCH({
|
|
18
|
-
url
|
|
19
|
-
}) {
|
|
20
|
-
const {
|
|
21
|
-
data
|
|
22
|
-
} = await window.fetch(url).then(res => res.json());
|
|
23
|
-
return data;
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
GET_DISPATCH: createRegistryControl(({
|
|
27
|
-
dispatch
|
|
28
|
-
}) => () => dispatch)
|
|
29
|
-
};
|
|
30
|
-
export default controls;
|
|
31
|
-
//# sourceMappingURL=controls.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/controls.js"],"names":["createRegistryControl","regularFetch","url","type","getDispatch","controls","REGULAR_FETCH","data","window","fetch","then","res","json","GET_DISPATCH","dispatch"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,qBAAT,QAAsC,iBAAtC;AAEA,OAAO,SAASC,YAAT,CAAuBC,GAAvB,EAA6B;AACnC,SAAO;AACNC,IAAAA,IAAI,EAAE,eADA;AAEND,IAAAA;AAFM,GAAP;AAIA;AAED,OAAO,SAASE,WAAT,GAAuB;AAC7B,SAAO;AACND,IAAAA,IAAI,EAAE;AADA,GAAP;AAGA;AAED,MAAME,QAAQ,GAAG;AAChB,QAAMC,aAAN,CAAqB;AAAEJ,IAAAA;AAAF,GAArB,EAA+B;AAC9B,UAAM;AAAEK,MAAAA;AAAF,QAAW,MAAMC,MAAM,CAC3BC,KADqB,CACdP,GADc,EAErBQ,IAFqB,CAEbC,GAAF,IAAWA,GAAG,CAACC,IAAJ,EAFI,CAAvB;AAIA,WAAOL,IAAP;AACA,GAPe;;AAShBM,EAAAA,YAAY,EAAEb,qBAAqB,CAAE,CAAE;AAAEc,IAAAA;AAAF,GAAF,KAAoB,MAAMA,QAA5B;AATnB,CAAjB;AAYA,eAAeT,QAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createRegistryControl } from '@wordpress/data';\n\nexport function regularFetch( url ) {\n\treturn {\n\t\ttype: 'REGULAR_FETCH',\n\t\turl,\n\t};\n}\n\nexport function getDispatch() {\n\treturn {\n\t\ttype: 'GET_DISPATCH',\n\t};\n}\n\nconst controls = {\n\tasync REGULAR_FETCH( { url } ) {\n\t\tconst { data } = await window\n\t\t\t.fetch( url )\n\t\t\t.then( ( res ) => res.json() );\n\n\t\treturn data;\n\t},\n\n\tGET_DISPATCH: createRegistryControl( ( { dispatch } ) => () => dispatch ),\n};\n\nexport default controls;\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/locks/index.js"],"names":["default","reducer"],"mappings":"AAAA,cAAc,WAAd;AACA,cAAc,aAAd;AACA,SAASA,OAAO,IAAIC,OAApB,QAAmC,WAAnC","sourcesContent":["export * from './actions';\nexport * from './selectors';\nexport { default as reducer } from './reducer';\n"]}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { controls } from '@wordpress/data';
|
|
5
|
-
/**
|
|
6
|
-
* Internal dependencies
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { STORE_NAME } from '../name';
|
|
10
|
-
/**
|
|
11
|
-
* Higher-order function which invokes the given resolver only if it has not
|
|
12
|
-
* already been resolved with the arguments passed to the enhanced function.
|
|
13
|
-
*
|
|
14
|
-
* This only considers resolution state, and notably does not support resolver
|
|
15
|
-
* custom `isFulfilled` behavior.
|
|
16
|
-
*
|
|
17
|
-
* @param {Function} resolver Original resolver.
|
|
18
|
-
* @param {string} selectorName Selector name associated with resolver.
|
|
19
|
-
*
|
|
20
|
-
* @return {Function} Enhanced resolver.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
const ifNotResolved = (resolver, selectorName) =>
|
|
24
|
-
/**
|
|
25
|
-
* @param {...any} args Original resolver arguments.
|
|
26
|
-
*/
|
|
27
|
-
function* resolveIfNotResolved(...args) {
|
|
28
|
-
const hasStartedResolution = yield controls.select(STORE_NAME, 'hasStartedResolution', selectorName, args);
|
|
29
|
-
|
|
30
|
-
if (!hasStartedResolution) {
|
|
31
|
-
yield* resolver(...args);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export default ifNotResolved;
|
|
36
|
-
//# sourceMappingURL=if-not-resolved.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/utils/if-not-resolved.js"],"names":["controls","STORE_NAME","ifNotResolved","resolver","selectorName","resolveIfNotResolved","args","hasStartedResolution","select"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAT,QAAyB,iBAAzB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,SAA3B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,aAAa,GAAG,CAAEC,QAAF,EAAYC,YAAZ;AACrB;AACD;AACA;AACC,UAAUC,oBAAV,CAAgC,GAAGC,IAAnC,EAA0C;AACzC,QAAMC,oBAAoB,GAAG,MAAMP,QAAQ,CAACQ,MAAT,CAClCP,UADkC,EAElC,sBAFkC,EAGlCG,YAHkC,EAIlCE,IAJkC,CAAnC;;AAOA,MAAK,CAAEC,oBAAP,EAA8B;AAC7B,WAAOJ,QAAQ,CAAE,GAAGG,IAAL,CAAf;AACA;AACD,CAfF;;AAiBA,eAAeJ,aAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { controls } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from '../name';\n\n/**\n * Higher-order function which invokes the given resolver only if it has not\n * already been resolved with the arguments passed to the enhanced function.\n *\n * This only considers resolution state, and notably does not support resolver\n * custom `isFulfilled` behavior.\n *\n * @param {Function} resolver Original resolver.\n * @param {string} selectorName Selector name associated with resolver.\n *\n * @return {Function} Enhanced resolver.\n */\nconst ifNotResolved = ( resolver, selectorName ) =>\n\t/**\n\t * @param {...any} args Original resolver arguments.\n\t */\n\tfunction* resolveIfNotResolved( ...args ) {\n\t\tconst hasStartedResolution = yield controls.select(\n\t\t\tSTORE_NAME,\n\t\t\t'hasStartedResolution',\n\t\t\tselectorName,\n\t\t\targs\n\t\t);\n\n\t\tif ( ! hasStartedResolution ) {\n\t\t\tyield* resolver( ...args );\n\t\t}\n\t};\n\nexport default ifNotResolved;\n"]}
|
package/src/controls.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { createRegistryControl } from '@wordpress/data';
|
|
5
|
-
|
|
6
|
-
export function regularFetch( url ) {
|
|
7
|
-
return {
|
|
8
|
-
type: 'REGULAR_FETCH',
|
|
9
|
-
url,
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function getDispatch() {
|
|
14
|
-
return {
|
|
15
|
-
type: 'GET_DISPATCH',
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const controls = {
|
|
20
|
-
async REGULAR_FETCH( { url } ) {
|
|
21
|
-
const { data } = await window
|
|
22
|
-
.fetch( url )
|
|
23
|
-
.then( ( res ) => res.json() );
|
|
24
|
-
|
|
25
|
-
return data;
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
GET_DISPATCH: createRegistryControl( ( { dispatch } ) => () => dispatch ),
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export default controls;
|
package/src/locks/index.js
DELETED