@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/build-module/index.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { createReduxStore, register } from '@wordpress/data';
|
|
5
|
-
import { controls } from '@wordpress/data-controls';
|
|
6
5
|
/**
|
|
7
6
|
* Internal dependencies
|
|
8
7
|
*/
|
|
@@ -11,9 +10,7 @@ import reducer from './reducer';
|
|
|
11
10
|
import * as selectors from './selectors';
|
|
12
11
|
import * as actions from './actions';
|
|
13
12
|
import * as resolvers from './resolvers';
|
|
14
|
-
import
|
|
15
|
-
import * as locksActions from './locks/actions';
|
|
16
|
-
import customControls from './controls';
|
|
13
|
+
import createLocksActions from './locks/actions';
|
|
17
14
|
import { defaultEntities, getMethodName } from './entities';
|
|
18
15
|
import { STORE_NAME } from './name'; // The entity selectors/resolvers and actions are shortcuts to their generic equivalents
|
|
19
16
|
// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecordss)
|
|
@@ -60,23 +57,21 @@ const entityActions = defaultEntities.reduce((result, entity) => {
|
|
|
60
57
|
|
|
61
58
|
return result;
|
|
62
59
|
}, {});
|
|
63
|
-
|
|
60
|
+
|
|
61
|
+
const storeConfig = () => ({
|
|
64
62
|
reducer,
|
|
65
|
-
controls: { ...customControls,
|
|
66
|
-
...controls
|
|
67
|
-
},
|
|
68
63
|
actions: { ...actions,
|
|
69
64
|
...entityActions,
|
|
70
|
-
...
|
|
65
|
+
...createLocksActions()
|
|
71
66
|
},
|
|
72
67
|
selectors: { ...selectors,
|
|
73
|
-
...entitySelectors
|
|
74
|
-
...locksSelectors
|
|
68
|
+
...entitySelectors
|
|
75
69
|
},
|
|
76
70
|
resolvers: { ...resolvers,
|
|
77
71
|
...entityResolvers
|
|
78
|
-
}
|
|
79
|
-
|
|
72
|
+
},
|
|
73
|
+
__experimentalUseThunks: true
|
|
74
|
+
});
|
|
80
75
|
/**
|
|
81
76
|
* Store definition for the code data namespace.
|
|
82
77
|
*
|
|
@@ -85,7 +80,8 @@ const storeConfig = {
|
|
|
85
80
|
* @type {Object}
|
|
86
81
|
*/
|
|
87
82
|
|
|
88
|
-
|
|
83
|
+
|
|
84
|
+
export const store = createReduxStore(STORE_NAME, storeConfig());
|
|
89
85
|
register(store);
|
|
90
86
|
export { default as EntityProvider } from './entity-provider';
|
|
91
87
|
export * from './entity-provider';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["createReduxStore","register","
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["createReduxStore","register","reducer","selectors","actions","resolvers","createLocksActions","defaultEntities","getMethodName","STORE_NAME","entitySelectors","reduce","result","entity","kind","name","state","key","query","getEntityRecord","args","getEntityRecords","entityResolvers","pluralMethodName","shouldInvalidate","action","entityActions","saveEntityRecord","deleteEntityRecord","storeConfig","__experimentalUseThunks","store","default","EntityProvider"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAT,EAA2BC,QAA3B,QAA2C,iBAA3C;AAEA;AACA;AACA;;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAO,KAAKC,SAAZ,MAA2B,aAA3B;AACA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A,OAAL;AAAc,OAAGsB,aAAjB;AAAgC,OAAGpB,kBAAkB;AAArD,GAFkB;AAG3BH,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGO;AAAnB,GAHgB;AAI3BL,EAAAA,SAAS,EAAE,EAAE,GAAGA,SAAL;AAAgB,OAAGiB;AAAnB,GAJgB;AAK3BQ,EAAAA,uBAAuB,EAAE;AALE,CAAR,CAApB;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,MAAMC,KAAK,GAAG/B,gBAAgB,CAAES,UAAF,EAAcoB,WAAW,EAAzB,CAA9B;AAEP5B,QAAQ,CAAE8B,KAAF,CAAR;AAEA,SAASC,OAAO,IAAIC,cAApB,QAA0C,mBAA1C;AACA,cAAc,mBAAd;AACA,cAAc,SAAd","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { defaultEntities, getMethodName } from './entities';\nimport { STORE_NAME } from './name';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecordss)\n// Instead of getEntityRecord, the consumer could use more user-frieldly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = defaultEntities.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\tresult[ getMethodName( kind, name, 'get', true ) ] = ( state, ...args ) =>\n\t\tselectors.getEntityRecords( state, kind, name, ...args );\n\treturn result;\n}, {} );\n\nconst entityResolvers = defaultEntities.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\tconst pluralMethodName = getMethodName( kind, name, 'get', true );\n\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\tresolvers.getEntityRecords( kind, name, ...args );\n\tresult[ pluralMethodName ].shouldInvalidate = ( action, ...args ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate(\n\t\t\taction,\n\t\t\tkind,\n\t\t\tname,\n\t\t\t...args\n\t\t);\n\treturn result;\n}, {} );\n\nconst entityActions = defaultEntities.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( key ) =>\n\t\tactions.saveEntityRecord( kind, name, key );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: { ...actions, ...entityActions, ...createLocksActions() },\n\tselectors: { ...selectors, ...entitySelectors },\n\tresolvers: { ...resolvers, ...entityResolvers },\n\t__experimentalUseThunks: true,\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\n\nregister( store );\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './fetch';\n"]}
|
|
@@ -1,77 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { __unstableAwaitPromise } from '@wordpress/data-controls';
|
|
5
|
-
import { controls } from '@wordpress/data';
|
|
6
1
|
/**
|
|
7
2
|
* Internal dependencies
|
|
8
3
|
*/
|
|
4
|
+
import createLocks from './engine';
|
|
5
|
+
export default function createLocksActions() {
|
|
6
|
+
const locks = createLocks();
|
|
9
7
|
|
|
10
|
-
|
|
11
|
-
export function* __unstableAcquireStoreLock(store, path, {
|
|
12
|
-
exclusive
|
|
13
|
-
}) {
|
|
14
|
-
const promise = yield* __unstableEnqueueLockRequest(store, path, {
|
|
8
|
+
function __unstableAcquireStoreLock(store, path, {
|
|
15
9
|
exclusive
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
export function* __unstableEnqueueLockRequest(store, path, {
|
|
21
|
-
exclusive
|
|
22
|
-
}) {
|
|
23
|
-
let notifyAcquired;
|
|
24
|
-
const promise = new Promise(resolve => {
|
|
25
|
-
notifyAcquired = resolve;
|
|
26
|
-
});
|
|
27
|
-
yield {
|
|
28
|
-
type: 'ENQUEUE_LOCK_REQUEST',
|
|
29
|
-
request: {
|
|
30
|
-
store,
|
|
31
|
-
path,
|
|
32
|
-
exclusive,
|
|
33
|
-
notifyAcquired
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
return promise;
|
|
37
|
-
}
|
|
38
|
-
export function* __unstableReleaseStoreLock(lock) {
|
|
39
|
-
yield {
|
|
40
|
-
type: 'RELEASE_LOCK',
|
|
41
|
-
lock
|
|
42
|
-
};
|
|
43
|
-
yield* __unstableProcessPendingLockRequests();
|
|
44
|
-
}
|
|
45
|
-
export function* __unstableProcessPendingLockRequests() {
|
|
46
|
-
yield {
|
|
47
|
-
type: 'PROCESS_PENDING_LOCK_REQUESTS'
|
|
48
|
-
};
|
|
49
|
-
const lockRequests = yield controls.select(STORE_NAME, '__unstableGetPendingLockRequests');
|
|
50
|
-
|
|
51
|
-
for (const request of lockRequests) {
|
|
52
|
-
const {
|
|
53
|
-
store,
|
|
54
|
-
path,
|
|
55
|
-
exclusive,
|
|
56
|
-
notifyAcquired
|
|
57
|
-
} = request;
|
|
58
|
-
const isAvailable = yield controls.select(STORE_NAME, '__unstableIsLockAvailable', store, path, {
|
|
59
|
-
exclusive
|
|
60
|
-
});
|
|
10
|
+
}) {
|
|
11
|
+
return () => locks.acquire(store, path, exclusive);
|
|
12
|
+
}
|
|
61
13
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
store,
|
|
65
|
-
path,
|
|
66
|
-
exclusive
|
|
67
|
-
};
|
|
68
|
-
yield {
|
|
69
|
-
type: 'GRANT_LOCK_REQUEST',
|
|
70
|
-
lock,
|
|
71
|
-
request
|
|
72
|
-
};
|
|
73
|
-
notifyAcquired(lock);
|
|
74
|
-
}
|
|
14
|
+
function __unstableReleaseStoreLock(lock) {
|
|
15
|
+
return () => locks.release(lock);
|
|
75
16
|
}
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
__unstableAcquireStoreLock,
|
|
20
|
+
__unstableReleaseStoreLock
|
|
21
|
+
};
|
|
76
22
|
}
|
|
77
23
|
//# sourceMappingURL=actions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/locks/actions.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/locks/actions.js"],"names":["createLocks","createLocksActions","locks","__unstableAcquireStoreLock","store","path","exclusive","acquire","__unstableReleaseStoreLock","lock","release"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAP,MAAwB,UAAxB;AAEA,eAAe,SAASC,kBAAT,GAA8B;AAC5C,QAAMC,KAAK,GAAGF,WAAW,EAAzB;;AAEA,WAASG,0BAAT,CAAqCC,KAArC,EAA4CC,IAA5C,EAAkD;AAAEC,IAAAA;AAAF,GAAlD,EAAkE;AACjE,WAAO,MAAMJ,KAAK,CAACK,OAAN,CAAeH,KAAf,EAAsBC,IAAtB,EAA4BC,SAA5B,CAAb;AACA;;AAED,WAASE,0BAAT,CAAqCC,IAArC,EAA4C;AAC3C,WAAO,MAAMP,KAAK,CAACQ,OAAN,CAAeD,IAAf,CAAb;AACA;;AAED,SAAO;AAAEN,IAAAA,0BAAF;AAA8BK,IAAAA;AAA9B,GAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport createLocks from './engine';\n\nexport default function createLocksActions() {\n\tconst locks = createLocks();\n\n\tfunction __unstableAcquireStoreLock( store, path, { exclusive } ) {\n\t\treturn () => locks.acquire( store, path, exclusive );\n\t}\n\n\tfunction __unstableReleaseStoreLock( lock ) {\n\t\treturn () => locks.release( lock );\n\t}\n\n\treturn { __unstableAcquireStoreLock, __unstableReleaseStoreLock };\n}\n"]}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import reducer from './reducer';
|
|
5
|
+
import { isLockAvailable, getPendingLockRequests } from './selectors';
|
|
6
|
+
export default function createLocks() {
|
|
7
|
+
let state = reducer(undefined, {
|
|
8
|
+
type: '@@INIT'
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
function processPendingLockRequests() {
|
|
12
|
+
for (const request of getPendingLockRequests(state)) {
|
|
13
|
+
const {
|
|
14
|
+
store,
|
|
15
|
+
path,
|
|
16
|
+
exclusive,
|
|
17
|
+
notifyAcquired
|
|
18
|
+
} = request;
|
|
19
|
+
|
|
20
|
+
if (isLockAvailable(state, store, path, {
|
|
21
|
+
exclusive
|
|
22
|
+
})) {
|
|
23
|
+
const lock = {
|
|
24
|
+
store,
|
|
25
|
+
path,
|
|
26
|
+
exclusive
|
|
27
|
+
};
|
|
28
|
+
state = reducer(state, {
|
|
29
|
+
type: 'GRANT_LOCK_REQUEST',
|
|
30
|
+
lock,
|
|
31
|
+
request
|
|
32
|
+
});
|
|
33
|
+
notifyAcquired(lock);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function acquire(store, path, exclusive) {
|
|
39
|
+
return new Promise(resolve => {
|
|
40
|
+
state = reducer(state, {
|
|
41
|
+
type: 'ENQUEUE_LOCK_REQUEST',
|
|
42
|
+
request: {
|
|
43
|
+
store,
|
|
44
|
+
path,
|
|
45
|
+
exclusive,
|
|
46
|
+
notifyAcquired: resolve
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
processPendingLockRequests();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function release(lock) {
|
|
54
|
+
state = reducer(state, {
|
|
55
|
+
type: 'RELEASE_LOCK',
|
|
56
|
+
lock
|
|
57
|
+
});
|
|
58
|
+
processPendingLockRequests();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
acquire,
|
|
63
|
+
release
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/locks/engine.js"],"names":["reducer","isLockAvailable","getPendingLockRequests","createLocks","state","undefined","type","processPendingLockRequests","request","store","path","exclusive","notifyAcquired","lock","acquire","Promise","resolve","release"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,WAApB;AACA,SAASC,eAAT,EAA0BC,sBAA1B,QAAwD,aAAxD;AAEA,eAAe,SAASC,WAAT,GAAuB;AACrC,MAAIC,KAAK,GAAGJ,OAAO,CAAEK,SAAF,EAAa;AAAEC,IAAAA,IAAI,EAAE;AAAR,GAAb,CAAnB;;AAEA,WAASC,0BAAT,GAAsC;AACrC,SAAM,MAAMC,OAAZ,IAAuBN,sBAAsB,CAAEE,KAAF,CAA7C,EAAyD;AACxD,YAAM;AAAEK,QAAAA,KAAF;AAASC,QAAAA,IAAT;AAAeC,QAAAA,SAAf;AAA0BC,QAAAA;AAA1B,UAA6CJ,OAAnD;;AACA,UAAKP,eAAe,CAAEG,KAAF,EAASK,KAAT,EAAgBC,IAAhB,EAAsB;AAAEC,QAAAA;AAAF,OAAtB,CAApB,EAA4D;AAC3D,cAAME,IAAI,GAAG;AAAEJ,UAAAA,KAAF;AAASC,UAAAA,IAAT;AAAeC,UAAAA;AAAf,SAAb;AACAP,QAAAA,KAAK,GAAGJ,OAAO,CAAEI,KAAF,EAAS;AACvBE,UAAAA,IAAI,EAAE,oBADiB;AAEvBO,UAAAA,IAFuB;AAGvBL,UAAAA;AAHuB,SAAT,CAAf;AAKAI,QAAAA,cAAc,CAAEC,IAAF,CAAd;AACA;AACD;AACD;;AAED,WAASC,OAAT,CAAkBL,KAAlB,EAAyBC,IAAzB,EAA+BC,SAA/B,EAA2C;AAC1C,WAAO,IAAII,OAAJ,CAAeC,OAAF,IAAe;AAClCZ,MAAAA,KAAK,GAAGJ,OAAO,CAAEI,KAAF,EAAS;AACvBE,QAAAA,IAAI,EAAE,sBADiB;AAEvBE,QAAAA,OAAO,EAAE;AAAEC,UAAAA,KAAF;AAASC,UAAAA,IAAT;AAAeC,UAAAA,SAAf;AAA0BC,UAAAA,cAAc,EAAEI;AAA1C;AAFc,OAAT,CAAf;AAIAT,MAAAA,0BAA0B;AAC1B,KANM,CAAP;AAOA;;AACD,WAASU,OAAT,CAAkBJ,IAAlB,EAAyB;AACxBT,IAAAA,KAAK,GAAGJ,OAAO,CAAEI,KAAF,EAAS;AACvBE,MAAAA,IAAI,EAAE,cADiB;AAEvBO,MAAAA;AAFuB,KAAT,CAAf;AAIAN,IAAAA,0BAA0B;AAC1B;;AAED,SAAO;AAAEO,IAAAA,OAAF;AAAWG,IAAAA;AAAX,GAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport { isLockAvailable, getPendingLockRequests } from './selectors';\n\nexport default function createLocks() {\n\tlet state = reducer( undefined, { type: '@@INIT' } );\n\n\tfunction processPendingLockRequests() {\n\t\tfor ( const request of getPendingLockRequests( state ) ) {\n\t\t\tconst { store, path, exclusive, notifyAcquired } = request;\n\t\t\tif ( isLockAvailable( state, store, path, { exclusive } ) ) {\n\t\t\t\tconst lock = { store, path, exclusive };\n\t\t\t\tstate = reducer( state, {\n\t\t\t\t\ttype: 'GRANT_LOCK_REQUEST',\n\t\t\t\t\tlock,\n\t\t\t\t\trequest,\n\t\t\t\t} );\n\t\t\t\tnotifyAcquired( lock );\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction acquire( store, path, exclusive ) {\n\t\treturn new Promise( ( resolve ) => {\n\t\t\tstate = reducer( state, {\n\t\t\t\ttype: 'ENQUEUE_LOCK_REQUEST',\n\t\t\t\trequest: { store, path, exclusive, notifyAcquired: resolve },\n\t\t\t} );\n\t\t\tprocessPendingLockRequests();\n\t\t} );\n\t}\n\tfunction release( lock ) {\n\t\tstate = reducer( state, {\n\t\t\ttype: 'RELEASE_LOCK',\n\t\t\tlock,\n\t\t} );\n\t\tprocessPendingLockRequests();\n\t}\n\n\treturn { acquire, release };\n}\n"]}
|
|
@@ -18,7 +18,7 @@ const DEFAULT_STATE = {
|
|
|
18
18
|
* @return {Object} Updated state.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
|
-
export function locks(state = DEFAULT_STATE, action) {
|
|
21
|
+
export default function locks(state = DEFAULT_STATE, action) {
|
|
22
22
|
switch (action.type) {
|
|
23
23
|
case 'ENQUEUE_LOCK_REQUEST':
|
|
24
24
|
{
|
|
@@ -67,5 +67,4 @@ export function locks(state = DEFAULT_STATE, action) {
|
|
|
67
67
|
|
|
68
68
|
return state;
|
|
69
69
|
}
|
|
70
|
-
export default locks;
|
|
71
70
|
//# sourceMappingURL=reducer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/locks/reducer.js"],"names":["getNode","deepCopyLocksTreePath","DEFAULT_STATE","requests","tree","locks","children","state","action","type","request","lock","store","path","storePath","newTree","node","filter","r","l"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,qBAAlB,QAA+C,SAA/C;AAEA,MAAMC,aAAa,GAAG;AACrBC,EAAAA,QAAQ,EAAE,EADW;AAErBC,EAAAA,IAAI,EAAE;AACLC,IAAAA,KAAK,EAAE,EADF;AAELC,IAAAA,QAAQ,EAAE;AAFL;AAFe,CAAtB;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/locks/reducer.js"],"names":["getNode","deepCopyLocksTreePath","DEFAULT_STATE","requests","tree","locks","children","state","action","type","request","lock","store","path","storePath","newTree","node","filter","r","l"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,qBAAlB,QAA+C,SAA/C;AAEA,MAAMC,aAAa,GAAG;AACrBC,EAAAA,QAAQ,EAAE,EADW;AAErBC,EAAAA,IAAI,EAAE;AACLC,IAAAA,KAAK,EAAE,EADF;AAELC,IAAAA,QAAQ,EAAE;AAFL;AAFe,CAAtB;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASD,KAAT,CAAgBE,KAAK,GAAGL,aAAxB,EAAuCM,MAAvC,EAAgD;AAC9D,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,sBAAL;AAA6B;AAC5B,cAAM;AAAEC,UAAAA;AAAF,YAAcF,MAApB;AACA,eAAO,EACN,GAAGD,KADG;AAENJ,UAAAA,QAAQ,EAAE,CAAEO,OAAF,EAAW,GAAGH,KAAK,CAACJ,QAApB;AAFJ,SAAP;AAIA;;AACD,SAAK,oBAAL;AAA2B;AAC1B,cAAM;AAAEQ,UAAAA,IAAF;AAAQD,UAAAA;AAAR,YAAoBF,MAA1B;AACA,cAAM;AAAEI,UAAAA,KAAF;AAASC,UAAAA;AAAT,YAAkBH,OAAxB;AACA,cAAMI,SAAS,GAAG,CAAEF,KAAF,EAAS,GAAGC,IAAZ,CAAlB;AAEA,cAAME,OAAO,GAAGd,qBAAqB,CAAEM,KAAK,CAACH,IAAR,EAAcU,SAAd,CAArC;AACA,cAAME,IAAI,GAAGhB,OAAO,CAAEe,OAAF,EAAWD,SAAX,CAApB;AACAE,QAAAA,IAAI,CAACX,KAAL,GAAa,CAAE,GAAGW,IAAI,CAACX,KAAV,EAAiBM,IAAjB,CAAb;AAEA,eAAO,EACN,GAAGJ,KADG;AAENJ,UAAAA,QAAQ,EAAEI,KAAK,CAACJ,QAAN,CAAec,MAAf,CAAyBC,CAAF,IAASA,CAAC,KAAKR,OAAtC,CAFJ;AAGNN,UAAAA,IAAI,EAAEW;AAHA,SAAP;AAKA;;AACD,SAAK,cAAL;AAAqB;AACpB,cAAM;AAAEJ,UAAAA;AAAF,YAAWH,MAAjB;AACA,cAAMM,SAAS,GAAG,CAAEH,IAAI,CAACC,KAAP,EAAc,GAAGD,IAAI,CAACE,IAAtB,CAAlB;AAEA,cAAME,OAAO,GAAGd,qBAAqB,CAAEM,KAAK,CAACH,IAAR,EAAcU,SAAd,CAArC;AACA,cAAME,IAAI,GAAGhB,OAAO,CAAEe,OAAF,EAAWD,SAAX,CAApB;AACAE,QAAAA,IAAI,CAACX,KAAL,GAAaW,IAAI,CAACX,KAAL,CAAWY,MAAX,CAAqBE,CAAF,IAASA,CAAC,KAAKR,IAAlC,CAAb;AAEA,eAAO,EACN,GAAGJ,KADG;AAENH,UAAAA,IAAI,EAAEW;AAFA,SAAP;AAIA;AAnCF;;AAsCA,SAAOR,KAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { getNode, deepCopyLocksTreePath } from './utils';\n\nconst DEFAULT_STATE = {\n\trequests: [],\n\ttree: {\n\t\tlocks: [],\n\t\tchildren: {},\n\t},\n};\n\n/**\n * Reducer returning locks.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport default function locks( state = DEFAULT_STATE, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'ENQUEUE_LOCK_REQUEST': {\n\t\t\tconst { request } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\trequests: [ request, ...state.requests ],\n\t\t\t};\n\t\t}\n\t\tcase 'GRANT_LOCK_REQUEST': {\n\t\t\tconst { lock, request } = action;\n\t\t\tconst { store, path } = request;\n\t\t\tconst storePath = [ store, ...path ];\n\n\t\t\tconst newTree = deepCopyLocksTreePath( state.tree, storePath );\n\t\t\tconst node = getNode( newTree, storePath );\n\t\t\tnode.locks = [ ...node.locks, lock ];\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\trequests: state.requests.filter( ( r ) => r !== request ),\n\t\t\t\ttree: newTree,\n\t\t\t};\n\t\t}\n\t\tcase 'RELEASE_LOCK': {\n\t\t\tconst { lock } = action;\n\t\t\tconst storePath = [ lock.store, ...lock.path ];\n\n\t\t\tconst newTree = deepCopyLocksTreePath( state.tree, storePath );\n\t\t\tconst node = getNode( newTree, storePath );\n\t\t\tnode.locks = node.locks.filter( ( l ) => l !== lock );\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\ttree: newTree,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn state;\n}\n"]}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { iterateDescendants, iteratePath, hasConflictingLock, getNode } from './utils';
|
|
5
|
-
export function
|
|
6
|
-
return state.
|
|
5
|
+
export function getPendingLockRequests(state) {
|
|
6
|
+
return state.requests;
|
|
7
7
|
}
|
|
8
|
-
export function
|
|
8
|
+
export function isLockAvailable(state, store, path, {
|
|
9
9
|
exclusive
|
|
10
10
|
}) {
|
|
11
11
|
const storePath = [store, ...path];
|
|
12
|
-
const locks = state.
|
|
12
|
+
const locks = state.tree; // Validate all parents and the node itself
|
|
13
13
|
|
|
14
14
|
for (const node of iteratePath(locks, storePath)) {
|
|
15
15
|
if (hasConflictingLock({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/locks/selectors.js"],"names":["iterateDescendants","iteratePath","hasConflictingLock","getNode","
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/locks/selectors.js"],"names":["iterateDescendants","iteratePath","hasConflictingLock","getNode","getPendingLockRequests","state","requests","isLockAvailable","store","path","exclusive","storePath","locks","tree","node","descendant"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,kBADD,EAECC,WAFD,EAGCC,kBAHD,EAICC,OAJD,QAKO,SALP;AAOA,OAAO,SAASC,sBAAT,CAAiCC,KAAjC,EAAyC;AAC/C,SAAOA,KAAK,CAACC,QAAb;AACA;AAED,OAAO,SAASC,eAAT,CAA0BF,KAA1B,EAAiCG,KAAjC,EAAwCC,IAAxC,EAA8C;AAAEC,EAAAA;AAAF,CAA9C,EAA8D;AACpE,QAAMC,SAAS,GAAG,CAAEH,KAAF,EAAS,GAAGC,IAAZ,CAAlB;AACA,QAAMG,KAAK,GAAGP,KAAK,CAACQ,IAApB,CAFoE,CAIpE;;AACA,OAAM,MAAMC,IAAZ,IAAoBb,WAAW,CAAEW,KAAF,EAASD,SAAT,CAA/B,EAAsD;AACrD,QAAKT,kBAAkB,CAAE;AAAEQ,MAAAA;AAAF,KAAF,EAAiBI,IAAI,CAACF,KAAtB,CAAvB,EAAuD;AACtD,aAAO,KAAP;AACA;AACD,GATmE,CAWpE;AACA;;;AACA,QAAME,IAAI,GAAGX,OAAO,CAAES,KAAF,EAASD,SAAT,CAApB;;AACA,MAAK,CAAEG,IAAP,EAAc;AACb,WAAO,IAAP;AACA,GAhBmE,CAkBpE;;;AACA,OAAM,MAAMC,UAAZ,IAA0Bf,kBAAkB,CAAEc,IAAF,CAA5C,EAAuD;AACtD,QAAKZ,kBAAkB,CAAE;AAAEQ,MAAAA;AAAF,KAAF,EAAiBK,UAAU,CAACH,KAA5B,CAAvB,EAA6D;AAC5D,aAAO,KAAP;AACA;AACD;;AAED,SAAO,IAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport {\n\titerateDescendants,\n\titeratePath,\n\thasConflictingLock,\n\tgetNode,\n} from './utils';\n\nexport function getPendingLockRequests( state ) {\n\treturn state.requests;\n}\n\nexport function isLockAvailable( state, store, path, { exclusive } ) {\n\tconst storePath = [ store, ...path ];\n\tconst locks = state.tree;\n\n\t// Validate all parents and the node itself\n\tfor ( const node of iteratePath( locks, storePath ) ) {\n\t\tif ( hasConflictingLock( { exclusive }, node.locks ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\t// iteratePath terminates early if path is unreachable, let's\n\t// re-fetch the node and check it exists in the tree.\n\tconst node = getNode( locks, storePath );\n\tif ( ! node ) {\n\t\treturn true;\n\t}\n\n\t// Validate all nested nodes\n\tfor ( const descendant of iterateDescendants( node ) ) {\n\t\tif ( hasConflictingLock( { exclusive }, descendant.locks ) ) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\treturn true;\n}\n"]}
|
|
@@ -19,6 +19,8 @@ import { withWeakMapCache, getNormalizedCommaSeparable } from '../utils';
|
|
|
19
19
|
* @property {?(string[])} fields Target subset of fields to derive from
|
|
20
20
|
* item objects.
|
|
21
21
|
* @property {?(number[])} include Specific item IDs to include.
|
|
22
|
+
* @property {string} context Scope under which the request is made;
|
|
23
|
+
* determines returned fields in response.
|
|
22
24
|
*/
|
|
23
25
|
|
|
24
26
|
/**
|
|
@@ -59,10 +61,6 @@ export function getQueryParts(query) {
|
|
|
59
61
|
parts.perPage = Number(value);
|
|
60
62
|
break;
|
|
61
63
|
|
|
62
|
-
case 'include':
|
|
63
|
-
parts.include = getNormalizedCommaSeparable(value).map(Number);
|
|
64
|
-
break;
|
|
65
|
-
|
|
66
64
|
case 'context':
|
|
67
65
|
parts.context = value;
|
|
68
66
|
break;
|
|
@@ -77,6 +75,13 @@ export function getQueryParts(query) {
|
|
|
77
75
|
parts.fields = getNormalizedCommaSeparable(value); // Make sure to normalize value for `stableKey`
|
|
78
76
|
|
|
79
77
|
value = parts.fields.join();
|
|
78
|
+
} // Two requests with different include values cannot have same results.
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
if (key === 'include') {
|
|
82
|
+
parts.include = getNormalizedCommaSeparable(value).map(Number); // Normalize value for `stableKey`.
|
|
83
|
+
|
|
84
|
+
value = parts.include.join();
|
|
80
85
|
} // While it could be any deterministic string, for simplicity's
|
|
81
86
|
// sake mimic querystring encoding for stable key.
|
|
82
87
|
//
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/queried-data/get-query-parts.js"],"names":["addQueryArgs","withWeakMapCache","getNormalizedCommaSeparable","getQueryParts","query","parts","stableKey","page","perPage","fields","include","context","keys","Object","sort","i","length","key","value","Number","
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/queried-data/get-query-parts.js"],"names":["addQueryArgs","withWeakMapCache","getNormalizedCommaSeparable","getQueryParts","query","parts","stableKey","page","perPage","fields","include","context","keys","Object","sort","i","length","key","value","Number","join","map","slice"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAT,QAA6B,gBAA7B;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,EAA2BC,2BAA3B,QAA8D,UAA9D;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,aAAT,CAAwBC,KAAxB,EAAgC;AACtC;AACD;AACA;AACC,QAAMC,KAAK,GAAG;AACbC,IAAAA,SAAS,EAAE,EADE;AAEbC,IAAAA,IAAI,EAAE,CAFO;AAGbC,IAAAA,OAAO,EAAE,EAHI;AAIbC,IAAAA,MAAM,EAAE,IAJK;AAKbC,IAAAA,OAAO,EAAE,IALI;AAMbC,IAAAA,OAAO,EAAE;AANI,GAAd,CAJsC,CAatC;;AACA,QAAMC,IAAI,GAAGC,MAAM,CAACD,IAAP,CAAaR,KAAb,EAAqBU,IAArB,EAAb;;AAEA,OAAM,IAAIC,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGH,IAAI,CAACI,MAA1B,EAAkCD,CAAC,EAAnC,EAAwC;AACvC,UAAME,GAAG,GAAGL,IAAI,CAAEG,CAAF,CAAhB;AACA,QAAIG,KAAK,GAAGd,KAAK,CAAEa,GAAF,CAAjB;;AAEA,YAASA,GAAT;AACC,WAAK,MAAL;AACCZ,QAAAA,KAAK,CAAEY,GAAF,CAAL,GAAeE,MAAM,CAAED,KAAF,CAArB;AACA;;AAED,WAAK,UAAL;AACCb,QAAAA,KAAK,CAACG,OAAN,GAAgBW,MAAM,CAAED,KAAF,CAAtB;AACA;;AAED,WAAK,SAAL;AACCb,QAAAA,KAAK,CAACM,OAAN,GAAgBO,KAAhB;AACA;;AAED;AACC;AACA;AACA;AACA;AACA;AACA,YAAKD,GAAG,KAAK,SAAb,EAAyB;AACxBZ,UAAAA,KAAK,CAACI,MAAN,GAAeP,2BAA2B,CAAEgB,KAAF,CAA1C,CADwB,CAExB;;AACAA,UAAAA,KAAK,GAAGb,KAAK,CAACI,MAAN,CAAaW,IAAb,EAAR;AACA,SAVF,CAYC;;;AACA,YAAKH,GAAG,KAAK,SAAb,EAAyB;AACxBZ,UAAAA,KAAK,CAACK,OAAN,GAAgBR,2BAA2B,CAAEgB,KAAF,CAA3B,CAAqCG,GAArC,CACfF,MADe,CAAhB,CADwB,CAIxB;;AACAD,UAAAA,KAAK,GAAGb,KAAK,CAACK,OAAN,CAAcU,IAAd,EAAR;AACA,SAnBF,CAqBC;AACA;AACA;AACA;AACA;AACA;AACA;;;AACAf,QAAAA,KAAK,CAACC,SAAN,IACC,CAAED,KAAK,CAACC,SAAN,GAAkB,GAAlB,GAAwB,EAA1B,IACAN,YAAY,CAAE,EAAF,EAAM;AAAE,WAAEiB,GAAF,GAASC;AAAX,SAAN,CAAZ,CAAuCI,KAAvC,CAA8C,CAA9C,CAFD;AAzCF;AA6CA;;AAED,SAAOjB,KAAP;AACA;AAED,eAAeJ,gBAAgB,CAAEE,aAAF,CAA/B","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport { withWeakMapCache, getNormalizedCommaSeparable } from '../utils';\n\n/**\n * An object of properties describing a specific query.\n *\n * @typedef {Object} WPQueriedDataQueryParts\n *\n * @property {number} page The query page (1-based index, default 1).\n * @property {number} perPage Items per page for query (default 10).\n * @property {string} stableKey An encoded stable string of all non-\n * pagination, non-fields query parameters.\n * @property {?(string[])} fields Target subset of fields to derive from\n * item objects.\n * @property {?(number[])} include Specific item IDs to include.\n * @property {string} context Scope under which the request is made;\n * determines returned fields in response.\n */\n\n/**\n * Given a query object, returns an object of parts, including pagination\n * details (`page` and `perPage`, or default values). All other properties are\n * encoded into a stable (idempotent) `stableKey` value.\n *\n * @param {Object} query Optional query object.\n *\n * @return {WPQueriedDataQueryParts} Query parts.\n */\nexport function getQueryParts( query ) {\n\t/**\n\t * @type {WPQueriedDataQueryParts}\n\t */\n\tconst parts = {\n\t\tstableKey: '',\n\t\tpage: 1,\n\t\tperPage: 10,\n\t\tfields: null,\n\t\tinclude: null,\n\t\tcontext: 'default',\n\t};\n\n\t// Ensure stable key by sorting keys. Also more efficient for iterating.\n\tconst keys = Object.keys( query ).sort();\n\n\tfor ( let i = 0; i < keys.length; i++ ) {\n\t\tconst key = keys[ i ];\n\t\tlet value = query[ key ];\n\n\t\tswitch ( key ) {\n\t\t\tcase 'page':\n\t\t\t\tparts[ key ] = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'per_page':\n\t\t\t\tparts.perPage = Number( value );\n\t\t\t\tbreak;\n\n\t\t\tcase 'context':\n\t\t\t\tparts.context = value;\n\t\t\t\tbreak;\n\n\t\t\tdefault:\n\t\t\t\t// While in theory, we could exclude \"_fields\" from the stableKey\n\t\t\t\t// because two request with different fields have the same results\n\t\t\t\t// We're not able to ensure that because the server can decide to omit\n\t\t\t\t// fields from the response even if we explicitely asked for it.\n\t\t\t\t// Example: Asking for titles in posts without title support.\n\t\t\t\tif ( key === '_fields' ) {\n\t\t\t\t\tparts.fields = getNormalizedCommaSeparable( value );\n\t\t\t\t\t// Make sure to normalize value for `stableKey`\n\t\t\t\t\tvalue = parts.fields.join();\n\t\t\t\t}\n\n\t\t\t\t// Two requests with different include values cannot have same results.\n\t\t\t\tif ( key === 'include' ) {\n\t\t\t\t\tparts.include = getNormalizedCommaSeparable( value ).map(\n\t\t\t\t\t\tNumber\n\t\t\t\t\t);\n\t\t\t\t\t// Normalize value for `stableKey`.\n\t\t\t\t\tvalue = parts.include.join();\n\t\t\t\t}\n\n\t\t\t\t// While it could be any deterministic string, for simplicity's\n\t\t\t\t// sake mimic querystring encoding for stable key.\n\t\t\t\t//\n\t\t\t\t// TODO: For consistency with PHP implementation, addQueryArgs\n\t\t\t\t// should accept a key value pair, which may optimize its\n\t\t\t\t// implementation for our use here, vs. iterating an object\n\t\t\t\t// with only a single key.\n\t\t\t\tparts.stableKey +=\n\t\t\t\t\t( parts.stableKey ? '&' : '' ) +\n\t\t\t\t\taddQueryArgs( '', { [ key ]: value } ).slice( 1 );\n\t\t}\n\t}\n\n\treturn parts;\n}\n\nexport default withWeakMapCache( getQueryParts );\n"]}
|
|
@@ -40,14 +40,7 @@ function getQueriedItemsUncached(state, query) {
|
|
|
40
40
|
} = getQueryParts(query);
|
|
41
41
|
let itemIds;
|
|
42
42
|
|
|
43
|
-
if (
|
|
44
|
-
// If the parsed query yields a set of IDs, but otherwise no filtering,
|
|
45
|
-
// it's safe to consider targeted item IDs as the include set. This
|
|
46
|
-
// doesn't guarantee that those objects have been queried, which is
|
|
47
|
-
// accounted for below in the loop `null` return.
|
|
48
|
-
itemIds = include; // TODO: Avoid storing the empty stable string in reducer, since it
|
|
49
|
-
// can be computed dynamically here always.
|
|
50
|
-
} else if ((_state$queries = state.queries) !== null && _state$queries !== void 0 && (_state$queries$contex = _state$queries[context]) !== null && _state$queries$contex !== void 0 && _state$queries$contex[stableKey]) {
|
|
43
|
+
if ((_state$queries = state.queries) !== null && _state$queries !== void 0 && (_state$queries$contex = _state$queries[context]) !== null && _state$queries$contex !== void 0 && _state$queries$contex[stableKey]) {
|
|
51
44
|
itemIds = state.queries[context][stableKey];
|
|
52
45
|
}
|
|
53
46
|
|
|
@@ -66,7 +59,8 @@ function getQueriedItemsUncached(state, query) {
|
|
|
66
59
|
|
|
67
60
|
if (Array.isArray(include) && !include.includes(itemId)) {
|
|
68
61
|
continue;
|
|
69
|
-
}
|
|
62
|
+
} // Having a target item ID doesn't guarantee that this object has been queried.
|
|
63
|
+
|
|
70
64
|
|
|
71
65
|
if (!((_state$items$context = state.items[context]) !== null && _state$items$context !== void 0 && _state$items$context.hasOwnProperty(itemId))) {
|
|
72
66
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/queried-data/selectors.js"],"names":["createSelector","EquivalentKeyMap","get","set","getQueryParts","queriedItemsCacheByState","WeakMap","getQueriedItemsUncached","state","query","stableKey","page","perPage","include","fields","context","itemIds","
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/queried-data/selectors.js"],"names":["createSelector","EquivalentKeyMap","get","set","getQueryParts","queriedItemsCacheByState","WeakMap","getQueriedItemsUncached","state","query","stableKey","page","perPage","include","fields","context","itemIds","queries","startOffset","endOffset","length","Math","min","items","i","itemId","Array","isArray","includes","hasOwnProperty","item","filteredItem","f","field","split","value","itemIsComplete","push","getQueriedItems","queriedItemsCache","queriedItems","undefined"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,cAAP,MAA2B,QAA3B;AACA,OAAOC,gBAAP,MAA6B,oBAA7B;AACA,SAASC,GAAT,EAAcC,GAAd,QAAyB,QAAzB;AAEA;AACA;AACA;;AACA,OAAOC,aAAP,MAA0B,mBAA1B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,wBAAwB,GAAG,IAAIC,OAAJ,EAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,uBAAT,CAAkCC,KAAlC,EAAyCC,KAAzC,EAAiD;AAAA;;AAChD,QAAM;AACLC,IAAAA,SADK;AAELC,IAAAA,IAFK;AAGLC,IAAAA,OAHK;AAILC,IAAAA,OAJK;AAKLC,IAAAA,MALK;AAMLC,IAAAA;AANK,MAOFX,aAAa,CAAEK,KAAF,CAPjB;AAQA,MAAIO,OAAJ;;AAEA,wBAAKR,KAAK,CAACS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4C,CAAtC","sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\nimport EquivalentKeyMap from 'equivalent-key-map';\nimport { get, set } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport getQueryParts from './get-query-parts';\n\n/**\n * Cache of state keys to EquivalentKeyMap where the inner map tracks queries\n * to their resulting items set. WeakMap allows garbage collection on expired\n * state references.\n *\n * @type {WeakMap<Object,EquivalentKeyMap>}\n */\nconst queriedItemsCacheByState = new WeakMap();\n\n/**\n * Returns items for a given query, or null if the items are not known.\n *\n * @param {Object} state State object.\n * @param {?Object} query Optional query.\n *\n * @return {?Array} Query items.\n */\nfunction getQueriedItemsUncached( state, query ) {\n\tconst {\n\t\tstableKey,\n\t\tpage,\n\t\tperPage,\n\t\tinclude,\n\t\tfields,\n\t\tcontext,\n\t} = getQueryParts( query );\n\tlet itemIds;\n\n\tif ( state.queries?.[ context ]?.[ stableKey ] ) {\n\t\titemIds = state.queries[ context ][ stableKey ];\n\t}\n\n\tif ( ! itemIds ) {\n\t\treturn null;\n\t}\n\n\tconst startOffset = perPage === -1 ? 0 : ( page - 1 ) * perPage;\n\tconst endOffset =\n\t\tperPage === -1\n\t\t\t? itemIds.length\n\t\t\t: Math.min( startOffset + perPage, itemIds.length );\n\n\tconst items = [];\n\tfor ( let i = startOffset; i < endOffset; i++ ) {\n\t\tconst itemId = itemIds[ i ];\n\t\tif ( Array.isArray( include ) && ! include.includes( itemId ) ) {\n\t\t\tcontinue;\n\t\t}\n\n\t\t// Having a target item ID doesn't guarantee that this object has been queried.\n\t\tif ( ! state.items[ context ]?.hasOwnProperty( itemId ) ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst item = state.items[ context ][ itemId ];\n\n\t\tlet filteredItem;\n\t\tif ( Array.isArray( fields ) ) {\n\t\t\tfilteredItem = {};\n\n\t\t\tfor ( let f = 0; f < fields.length; f++ ) {\n\t\t\t\tconst field = fields[ f ].split( '.' );\n\t\t\t\tconst value = get( item, field );\n\t\t\t\tset( filteredItem, field, value );\n\t\t\t}\n\t\t} else {\n\t\t\t// If expecting a complete item, validate that completeness, or\n\t\t\t// otherwise abort.\n\t\t\tif ( ! state.itemIsComplete[ context ]?.[ itemId ] ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tfilteredItem = item;\n\t\t}\n\n\t\titems.push( filteredItem );\n\t}\n\n\treturn items;\n}\n\n/**\n * Returns items for a given query, or null if the items are not known. Caches\n * result both per state (by reference) and per query (by deep equality).\n * The caching approach is intended to be durable to query objects which are\n * deeply but not referentially equal, since otherwise:\n *\n * `getQueriedItems( state, {} ) !== getQueriedItems( state, {} )`\n *\n * @param {Object} state State object.\n * @param {?Object} query Optional query.\n *\n * @return {?Array} Query items.\n */\nexport const getQueriedItems = createSelector( ( state, query = {} ) => {\n\tlet queriedItemsCache = queriedItemsCacheByState.get( state );\n\tif ( queriedItemsCache ) {\n\t\tconst queriedItems = queriedItemsCache.get( query );\n\t\tif ( queriedItems !== undefined ) {\n\t\t\treturn queriedItems;\n\t\t}\n\t} else {\n\t\tqueriedItemsCache = new EquivalentKeyMap();\n\t\tqueriedItemsCacheByState.set( state, queriedItemsCache );\n\t}\n\n\tconst items = getQueriedItemsUncached( state, query );\n\tqueriedItemsCache.set( query, items );\n\treturn items;\n} );\n"]}
|
package/build-module/reducer.js
CHANGED
|
@@ -15,7 +15,6 @@ import isShallowEqual from '@wordpress/is-shallow-equal';
|
|
|
15
15
|
import { ifMatchingAction, replaceAction } from './utils';
|
|
16
16
|
import { reducer as queriedDataReducer } from './queried-data';
|
|
17
17
|
import { defaultEntities, DEFAULT_ENTITY_KEY } from './entities';
|
|
18
|
-
import { reducer as locksReducer } from './locks';
|
|
19
18
|
/**
|
|
20
19
|
* Reducer managing terms state. Keyed by taxonomy slug, the value is either
|
|
21
20
|
* undefined (if no request has been made for given taxonomy), null (if a
|
|
@@ -117,38 +116,36 @@ export function currentTheme(state = undefined, action) {
|
|
|
117
116
|
return state;
|
|
118
117
|
}
|
|
119
118
|
/**
|
|
120
|
-
* Reducer managing
|
|
119
|
+
* Reducer managing the current global styles id.
|
|
121
120
|
*
|
|
122
|
-
* @param {
|
|
121
|
+
* @param {string} state Current state.
|
|
123
122
|
* @param {Object} action Dispatched action.
|
|
124
123
|
*
|
|
125
|
-
* @return {
|
|
124
|
+
* @return {string} Updated state.
|
|
126
125
|
*/
|
|
127
126
|
|
|
128
|
-
export function
|
|
127
|
+
export function currentGlobalStylesId(state = undefined, action) {
|
|
129
128
|
switch (action.type) {
|
|
130
|
-
case '
|
|
131
|
-
return
|
|
132
|
-
[action.currentTheme.stylesheet]: action.currentTheme
|
|
133
|
-
};
|
|
129
|
+
case 'RECEIVE_CURRENT_GLOBAL_STYLES_ID':
|
|
130
|
+
return action.id;
|
|
134
131
|
}
|
|
135
132
|
|
|
136
133
|
return state;
|
|
137
134
|
}
|
|
138
135
|
/**
|
|
139
|
-
* Reducer managing theme
|
|
136
|
+
* Reducer managing the theme base global styles.
|
|
140
137
|
*
|
|
141
|
-
* @param {
|
|
138
|
+
* @param {string} state Current state.
|
|
142
139
|
* @param {Object} action Dispatched action.
|
|
143
140
|
*
|
|
144
|
-
* @return {
|
|
141
|
+
* @return {string} Updated state.
|
|
145
142
|
*/
|
|
146
143
|
|
|
147
|
-
export function
|
|
144
|
+
export function themeBaseGlobalStyles(state = {}, action) {
|
|
148
145
|
switch (action.type) {
|
|
149
|
-
case '
|
|
146
|
+
case 'RECEIVE_THEME_GLOBAL_STYLES':
|
|
150
147
|
return { ...state,
|
|
151
|
-
|
|
148
|
+
[action.stylesheet]: action.globalStyles
|
|
152
149
|
};
|
|
153
150
|
}
|
|
154
151
|
|
|
@@ -504,15 +501,14 @@ export default combineReducers({
|
|
|
504
501
|
terms,
|
|
505
502
|
users,
|
|
506
503
|
currentTheme,
|
|
504
|
+
currentGlobalStylesId,
|
|
507
505
|
currentUser,
|
|
506
|
+
themeBaseGlobalStyles,
|
|
508
507
|
taxonomies,
|
|
509
|
-
themes,
|
|
510
|
-
themeSupports,
|
|
511
508
|
entities,
|
|
512
509
|
undo,
|
|
513
510
|
embedPreviews,
|
|
514
511
|
userPermissions,
|
|
515
|
-
autosaves
|
|
516
|
-
locks: locksReducer
|
|
512
|
+
autosaves
|
|
517
513
|
});
|
|
518
514
|
//# sourceMappingURL=reducer.js.map
|