@wordpress/data 6.3.0 → 6.3.1-next.a55ed9455a.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/use-select/index.js +1 -1
  3. package/build/components/use-select/index.js.map +1 -1
  4. package/build/factory.js +1 -1
  5. package/build/factory.js.map +1 -1
  6. package/build/plugins/persistence/index.js +114 -12
  7. package/build/plugins/persistence/index.js.map +1 -1
  8. package/build/redux-store/index.js +24 -8
  9. package/build/redux-store/index.js.map +1 -1
  10. package/build/redux-store/metadata/actions.js +47 -4
  11. package/build/redux-store/metadata/actions.js.map +1 -1
  12. package/build/redux-store/metadata/reducer.js +57 -4
  13. package/build/redux-store/metadata/reducer.js.map +1 -1
  14. package/build/redux-store/metadata/selectors.js +71 -7
  15. package/build/redux-store/metadata/selectors.js.map +1 -1
  16. package/build/registry.js +0 -2
  17. package/build/registry.js.map +1 -1
  18. package/build/resolvers-cache-middleware.js +3 -3
  19. package/build/resolvers-cache-middleware.js.map +1 -1
  20. package/build-module/components/use-select/index.js +1 -1
  21. package/build-module/components/use-select/index.js.map +1 -1
  22. package/build-module/factory.js +1 -1
  23. package/build-module/factory.js.map +1 -1
  24. package/build-module/plugins/persistence/index.js +111 -12
  25. package/build-module/plugins/persistence/index.js.map +1 -1
  26. package/build-module/redux-store/index.js +24 -8
  27. package/build-module/redux-store/index.js.map +1 -1
  28. package/build-module/redux-store/metadata/actions.js +43 -4
  29. package/build-module/redux-store/metadata/actions.js.map +1 -1
  30. package/build-module/redux-store/metadata/reducer.js +57 -4
  31. package/build-module/redux-store/metadata/reducer.js.map +1 -1
  32. package/build-module/redux-store/metadata/selectors.js +65 -7
  33. package/build-module/redux-store/metadata/selectors.js.map +1 -1
  34. package/build-module/registry.js +0 -2
  35. package/build-module/registry.js.map +1 -1
  36. package/build-module/resolvers-cache-middleware.js +3 -3
  37. package/build-module/resolvers-cache-middleware.js.map +1 -1
  38. package/build-types/redux-store/metadata/actions.d.ts +37 -4
  39. package/build-types/redux-store/metadata/actions.d.ts.map +1 -1
  40. package/build-types/redux-store/metadata/reducer.d.ts +10 -2
  41. package/build-types/redux-store/metadata/reducer.d.ts.map +1 -1
  42. package/build-types/redux-store/metadata/selectors.d.ts +40 -0
  43. package/build-types/redux-store/metadata/selectors.d.ts.map +1 -1
  44. package/build-types/types.d.ts.map +1 -1
  45. package/package.json +8 -8
  46. package/src/components/use-select/index.js +1 -1
  47. package/src/components/use-select/test/index.js +7 -7
  48. package/src/components/with-select/test/index.js +3 -3
  49. package/src/factory.js +1 -1
  50. package/src/plugins/persistence/index.js +142 -8
  51. package/src/plugins/persistence/test/index.js +405 -0
  52. package/src/redux-store/index.js +43 -15
  53. package/src/redux-store/metadata/actions.js +43 -4
  54. package/src/redux-store/metadata/reducer.ts +60 -9
  55. package/src/redux-store/metadata/selectors.js +60 -7
  56. package/src/redux-store/metadata/test/reducer.js +64 -24
  57. package/src/redux-store/metadata/test/selectors.js +263 -53
  58. package/src/redux-store/test/index.js +42 -0
  59. package/src/registry.js +0 -2
  60. package/src/resolvers-cache-middleware.js +4 -3
  61. package/src/test/controls.js +7 -7
  62. package/src/test/registry.js +6 -6
  63. package/src/types.ts +1 -3
  64. package/tsconfig.tsbuildinfo +1 -1
@@ -3,6 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.failResolution = failResolution;
7
+ exports.failResolutions = failResolutions;
6
8
  exports.finishResolution = finishResolution;
7
9
  exports.finishResolutions = finishResolutions;
8
10
  exports.invalidateResolution = invalidateResolution;
@@ -45,13 +47,33 @@ function finishResolution(selectorName, args) {
45
47
  args
46
48
  };
47
49
  }
50
+ /**
51
+ * Returns an action object used in signalling that selector resolution has
52
+ * failed.
53
+ *
54
+ * @param {string} selectorName Name of selector for which resolver triggered.
55
+ * @param {unknown[]} args Arguments to associate for uniqueness.
56
+ * @param {Error|unknown} error The error that caused the failure.
57
+ *
58
+ * @return {{ type: 'FAIL_RESOLUTION', selectorName: string, args: unknown[], error: Error|unknown }} Action object.
59
+ */
60
+
61
+
62
+ function failResolution(selectorName, args, error) {
63
+ return {
64
+ type: 'FAIL_RESOLUTION',
65
+ selectorName,
66
+ args,
67
+ error
68
+ };
69
+ }
48
70
  /**
49
71
  * Returns an action object used in signalling that a batch of selector resolutions has
50
72
  * started.
51
73
  *
52
- * @param {string} selectorName Name of selector for which resolver triggered.
74
+ * @param {string} selectorName Name of selector for which resolver triggered.
53
75
  * @param {unknown[][]} args Array of arguments to associate for uniqueness, each item
54
- * is associated to a resolution.
76
+ * is associated to a resolution.
55
77
  *
56
78
  * @return {{ type: 'START_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object.
57
79
  */
@@ -68,9 +90,9 @@ function startResolutions(selectorName, args) {
68
90
  * Returns an action object used in signalling that a batch of selector resolutions has
69
91
  * completed.
70
92
  *
71
- * @param {string} selectorName Name of selector for which resolver triggered.
93
+ * @param {string} selectorName Name of selector for which resolver triggered.
72
94
  * @param {unknown[][]} args Array of arguments to associate for uniqueness, each item
73
- * is associated to a resolution.
95
+ * is associated to a resolution.
74
96
  *
75
97
  * @return {{ type: 'FINISH_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object.
76
98
  */
@@ -83,6 +105,27 @@ function finishResolutions(selectorName, args) {
83
105
  args
84
106
  };
85
107
  }
108
+ /**
109
+ * Returns an action object used in signalling that a batch of selector resolutions has
110
+ * completed and at least one of them has failed.
111
+ *
112
+ * @param {string} selectorName Name of selector for which resolver triggered.
113
+ * @param {unknown[]} args Array of arguments to associate for uniqueness, each item
114
+ * is associated to a resolution.
115
+ * @param {(Error|unknown)[]} errors Array of errors to associate for uniqueness, each item
116
+ * is associated to a resolution.
117
+ * @return {{ type: 'FAIL_RESOLUTIONS', selectorName: string, args: unknown[], errors: Array<Error|unknown> }} Action object.
118
+ */
119
+
120
+
121
+ function failResolutions(selectorName, args, errors) {
122
+ return {
123
+ type: 'FAIL_RESOLUTIONS',
124
+ selectorName,
125
+ args,
126
+ errors
127
+ };
128
+ }
86
129
  /**
87
130
  * Returns an action object used in signalling that we should invalidate the resolution cache.
88
131
  *
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/redux-store/metadata/actions.js"],"names":["startResolution","selectorName","args","type","finishResolution","startResolutions","finishResolutions","invalidateResolution","invalidateResolutionForStore","invalidateResolutionForStoreSelector"],"mappings":";;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAT,CAA0BC,YAA1B,EAAwCC,IAAxC,EAA+C;AACrD,SAAO;AACNC,IAAAA,IAAI,EAAE,kBADA;AAENF,IAAAA,YAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,gBAAT,CAA2BH,YAA3B,EAAyCC,IAAzC,EAAgD;AACtD,SAAO;AACNC,IAAAA,IAAI,EAAE,mBADA;AAENF,IAAAA,YAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,gBAAT,CAA2BJ,YAA3B,EAAyCC,IAAzC,EAAgD;AACtD,SAAO;AACNC,IAAAA,IAAI,EAAE,mBADA;AAENF,IAAAA,YAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,iBAAT,CAA4BL,YAA5B,EAA0CC,IAA1C,EAAiD;AACvD,SAAO;AACNC,IAAAA,IAAI,EAAE,oBADA;AAENF,IAAAA,YAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASK,oBAAT,CAA+BN,YAA/B,EAA6CC,IAA7C,EAAoD;AAC1D,SAAO;AACNC,IAAAA,IAAI,EAAE,uBADA;AAENF,IAAAA,YAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASM,4BAAT,GAAwC;AAC9C,SAAO;AACNL,IAAAA,IAAI,EAAE;AADA,GAAP;AAGA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASM,oCAAT,CAA+CR,YAA/C,EAA8D;AACpE,SAAO;AACNE,IAAAA,IAAI,EAAE,0CADA;AAENF,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * Returns an action object used in signalling that selector resolution has\n * started.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[]} args Arguments to associate for uniqueness.\n *\n * @return {{ type: 'START_RESOLUTION', selectorName: string, args: unknown[] }} Action object.\n */\nexport function startResolution( selectorName, args ) {\n\treturn {\n\t\ttype: 'START_RESOLUTION',\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that selector resolution has\n * completed.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[]} args Arguments to associate for uniqueness.\n *\n * @return {{ type: 'FINISH_RESOLUTION', selectorName: string, args: unknown[] }} Action object.\n */\nexport function finishResolution( selectorName, args ) {\n\treturn {\n\t\ttype: 'FINISH_RESOLUTION',\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a batch of selector resolutions has\n * started.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[][]} args Array of arguments to associate for uniqueness, each item\n * is associated to a resolution.\n *\n * @return {{ type: 'START_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object.\n */\nexport function startResolutions( selectorName, args ) {\n\treturn {\n\t\ttype: 'START_RESOLUTIONS',\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a batch of selector resolutions has\n * completed.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[][]} args Array of arguments to associate for uniqueness, each item\n * is associated to a resolution.\n *\n * @return {{ type: 'FINISH_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object.\n */\nexport function finishResolutions( selectorName, args ) {\n\treturn {\n\t\ttype: 'FINISH_RESOLUTIONS',\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that we should invalidate the resolution cache.\n *\n * @param {string} selectorName Name of selector for which resolver should be invalidated.\n * @param {unknown[]} args Arguments to associate for uniqueness.\n *\n * @return {{ type: 'INVALIDATE_RESOLUTION', selectorName: string, args: any[] }} Action object.\n */\nexport function invalidateResolution( selectorName, args ) {\n\treturn {\n\t\ttype: 'INVALIDATE_RESOLUTION',\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the resolution\n * should be invalidated.\n *\n * @return {{ type: 'INVALIDATE_RESOLUTION_FOR_STORE' }} Action object.\n */\nexport function invalidateResolutionForStore() {\n\treturn {\n\t\ttype: 'INVALIDATE_RESOLUTION_FOR_STORE',\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the resolution cache for a\n * given selectorName should be invalidated.\n *\n * @param {string} selectorName Name of selector for which all resolvers should\n * be invalidated.\n *\n * @return {{ type: 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR', selectorName: string }} Action object.\n */\nexport function invalidateResolutionForStoreSelector( selectorName ) {\n\treturn {\n\t\ttype: 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR',\n\t\tselectorName,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/redux-store/metadata/actions.js"],"names":["startResolution","selectorName","args","type","finishResolution","failResolution","error","startResolutions","finishResolutions","failResolutions","errors","invalidateResolution","invalidateResolutionForStore","invalidateResolutionForStoreSelector"],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAT,CAA0BC,YAA1B,EAAwCC,IAAxC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,SAASC,oBAAT,CAA+BV,YAA/B,EAA6CC,IAA7C,EAAoD;AAC1D,SAAO;AACNC,IAAAA,IAAI,EAAE,uBADA;AAENF,IAAAA,YAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASU,4BAAT,GAAwC;AAC9C,SAAO;AACNT,IAAAA,IAAI,EAAE;AADA,GAAP;AAGA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASU,oCAAT,CAA+CZ,YAA/C,EAA8D;AACpE,SAAO;AACNE,IAAAA,IAAI,EAAE,0CADA;AAENF,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * Returns an action object used in signalling that selector resolution has\n * started.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[]} args Arguments to associate for uniqueness.\n *\n * @return {{ type: 'START_RESOLUTION', selectorName: string, args: unknown[] }} Action object.\n */\nexport function startResolution( selectorName, args ) {\n\treturn {\n\t\ttype: 'START_RESOLUTION',\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that selector resolution has\n * completed.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[]} args Arguments to associate for uniqueness.\n *\n * @return {{ type: 'FINISH_RESOLUTION', selectorName: string, args: unknown[] }} Action object.\n */\nexport function finishResolution( selectorName, args ) {\n\treturn {\n\t\ttype: 'FINISH_RESOLUTION',\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that selector resolution has\n * failed.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[]} args Arguments to associate for uniqueness.\n * @param {Error|unknown} error The error that caused the failure.\n *\n * @return {{ type: 'FAIL_RESOLUTION', selectorName: string, args: unknown[], error: Error|unknown }} Action object.\n */\nexport function failResolution( selectorName, args, error ) {\n\treturn {\n\t\ttype: 'FAIL_RESOLUTION',\n\t\tselectorName,\n\t\targs,\n\t\terror,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a batch of selector resolutions has\n * started.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[][]} args Array of arguments to associate for uniqueness, each item\n * is associated to a resolution.\n *\n * @return {{ type: 'START_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object.\n */\nexport function startResolutions( selectorName, args ) {\n\treturn {\n\t\ttype: 'START_RESOLUTIONS',\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a batch of selector resolutions has\n * completed.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[][]} args Array of arguments to associate for uniqueness, each item\n * is associated to a resolution.\n *\n * @return {{ type: 'FINISH_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object.\n */\nexport function finishResolutions( selectorName, args ) {\n\treturn {\n\t\ttype: 'FINISH_RESOLUTIONS',\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a batch of selector resolutions has\n * completed and at least one of them has failed.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[]} args Array of arguments to associate for uniqueness, each item\n * is associated to a resolution.\n * @param {(Error|unknown)[]} errors Array of errors to associate for uniqueness, each item\n * is associated to a resolution.\n * @return {{ type: 'FAIL_RESOLUTIONS', selectorName: string, args: unknown[], errors: Array<Error|unknown> }} Action object.\n */\nexport function failResolutions( selectorName, args, errors ) {\n\treturn {\n\t\ttype: 'FAIL_RESOLUTIONS',\n\t\tselectorName,\n\t\targs,\n\t\terrors,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that we should invalidate the resolution cache.\n *\n * @param {string} selectorName Name of selector for which resolver should be invalidated.\n * @param {unknown[]} args Arguments to associate for uniqueness.\n *\n * @return {{ type: 'INVALIDATE_RESOLUTION', selectorName: string, args: any[] }} Action object.\n */\nexport function invalidateResolution( selectorName, args ) {\n\treturn {\n\t\ttype: 'INVALIDATE_RESOLUTION',\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the resolution\n * should be invalidated.\n *\n * @return {{ type: 'INVALIDATE_RESOLUTION_FOR_STORE' }} Action object.\n */\nexport function invalidateResolutionForStore() {\n\treturn {\n\t\ttype: 'INVALIDATE_RESOLUTION_FOR_STORE',\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the resolution cache for a\n * given selectorName should be invalidated.\n *\n * @param {string} selectorName Name of selector for which all resolvers should\n * be invalidated.\n *\n * @return {{ type: 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR', selectorName: string }} Action object.\n */\nexport function invalidateResolutionForStoreSelector( selectorName ) {\n\treturn {\n\t\ttype: 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR',\n\t\tselectorName,\n\t};\n}\n"]}
@@ -33,27 +33,78 @@ const subKeysIsResolved = (0, _utils.onSubKey)('selectorName')(function () {
33
33
 
34
34
  switch (action.type) {
35
35
  case 'START_RESOLUTION':
36
+ {
37
+ const nextState = new _equivalentKeyMap.default(state);
38
+ nextState.set((0, _utils.selectorArgsToStateKey)(action.args), {
39
+ status: 'resolving'
40
+ });
41
+ return nextState;
42
+ }
43
+
36
44
  case 'FINISH_RESOLUTION':
37
45
  {
38
- const isStarting = action.type === 'START_RESOLUTION';
39
46
  const nextState = new _equivalentKeyMap.default(state);
40
- nextState.set((0, _utils.selectorArgsToStateKey)(action.args), isStarting);
47
+ nextState.set((0, _utils.selectorArgsToStateKey)(action.args), {
48
+ status: 'finished'
49
+ });
50
+ return nextState;
51
+ }
52
+
53
+ case 'FAIL_RESOLUTION':
54
+ {
55
+ const nextState = new _equivalentKeyMap.default(state);
56
+ nextState.set((0, _utils.selectorArgsToStateKey)(action.args), {
57
+ status: 'error',
58
+ error: action.error
59
+ });
41
60
  return nextState;
42
61
  }
43
62
 
44
63
  case 'START_RESOLUTIONS':
64
+ {
65
+ const nextState = new _equivalentKeyMap.default(state);
66
+
67
+ for (const resolutionArgs of action.args) {
68
+ nextState.set((0, _utils.selectorArgsToStateKey)(resolutionArgs), {
69
+ status: 'resolving'
70
+ });
71
+ }
72
+
73
+ return nextState;
74
+ }
75
+
45
76
  case 'FINISH_RESOLUTIONS':
46
77
  {
47
- const isStarting = action.type === 'START_RESOLUTIONS';
48
78
  const nextState = new _equivalentKeyMap.default(state);
49
79
 
50
80
  for (const resolutionArgs of action.args) {
51
- nextState.set((0, _utils.selectorArgsToStateKey)(resolutionArgs), isStarting);
81
+ nextState.set((0, _utils.selectorArgsToStateKey)(resolutionArgs), {
82
+ status: 'finished'
83
+ });
52
84
  }
53
85
 
54
86
  return nextState;
55
87
  }
56
88
 
89
+ case 'FAIL_RESOLUTIONS':
90
+ {
91
+ const nextState = new _equivalentKeyMap.default(state);
92
+ action.args.forEach((resolutionArgs, idx) => {
93
+ const resolutionState = {
94
+ status: 'error',
95
+ error: undefined
96
+ };
97
+ const error = action.errors[idx];
98
+
99
+ if (error) {
100
+ resolutionState.error = error;
101
+ }
102
+
103
+ nextState.set((0, _utils.selectorArgsToStateKey)(resolutionArgs), resolutionState);
104
+ });
105
+ return nextState;
106
+ }
107
+
57
108
  case 'INVALIDATE_RESOLUTION':
58
109
  {
59
110
  const nextState = new _equivalentKeyMap.default(state);
@@ -88,8 +139,10 @@ const isResolved = function () {
88
139
 
89
140
  case 'START_RESOLUTION':
90
141
  case 'FINISH_RESOLUTION':
142
+ case 'FAIL_RESOLUTION':
91
143
  case 'START_RESOLUTIONS':
92
144
  case 'FINISH_RESOLUTIONS':
145
+ case 'FAIL_RESOLUTIONS':
93
146
  case 'INVALIDATE_RESOLUTION':
94
147
  return subKeysIsResolved(state, action);
95
148
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/redux-store/metadata/reducer.ts"],"names":["subKeysIsResolved","state","EquivalentKeyMap","action","type","isStarting","nextState","set","args","resolutionArgs","delete","isResolved","selectorName"],"mappings":";;;;;;;;;AAGA;;AACA;;AAMA;;AAVA;AACA;AAC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IAAhB;AACC,SAAK,iCAAL;AACC,aAAO,EAAP;;AACD,SAAK,0CAAL;AACC,aAAO,iBAAKH,KAAL,EAAY,CAAEE,MAAM,CAACS,YAAT,CAAZ,IACJ,kBAAMX,KAAN,EAAa,CAAEE,MAAM,CAACS,YAAT,CAAb,CADI,GAEJX,KAFH;;AAGD,SAAK,kBAAL;AACA,SAAK,mBAAL;AACA,SAAK,mBAAL;AACA,SAAK,oBAAL;AACA,SAAK,uBAAL;AACC,aAAOD,iBAAiB,CAAEC,KAAF,EAASE,MAAT,CAAxB;AAZF;;AAcA,SAAOF,KAAP;AACA,CAhBD;;eAkBeU,U","sourcesContent":["/**\n * External dependencies\n */\nimport { omit, has } from 'lodash';\nimport EquivalentKeyMap from 'equivalent-key-map';\nimport type { Reducer } from 'redux';\n\n/**\n * Internal dependencies\n */\nimport { selectorArgsToStateKey, onSubKey } from './utils';\n\ntype Action =\n\t| ReturnType< typeof import('./actions').startResolution >\n\t| ReturnType< typeof import('./actions').finishResolution >\n\t| ReturnType< typeof import('./actions').startResolutions >\n\t| ReturnType< typeof import('./actions').finishResolutions >\n\t| ReturnType< typeof import('./actions').invalidateResolution >\n\t| ReturnType< typeof import('./actions').invalidateResolutionForStore >\n\t| ReturnType<\n\t\t\ttypeof import('./actions').invalidateResolutionForStoreSelector\n\t >;\n\nexport type State = EquivalentKeyMap< unknown[] | unknown, boolean >;\n\n/**\n * Reducer function returning next state for selector resolution of\n * subkeys, object form:\n *\n * selectorName -> EquivalentKeyMap<Array,boolean>\n */\nconst subKeysIsResolved: Reducer< Record< string, State >, Action > = onSubKey<\n\tState,\n\tAction\n>( 'selectorName' )( ( state = new EquivalentKeyMap(), action: Action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'START_RESOLUTION':\n\t\tcase 'FINISH_RESOLUTION': {\n\t\t\tconst isStarting = action.type === 'START_RESOLUTION';\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tnextState.set( selectorArgsToStateKey( action.args ), isStarting );\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'START_RESOLUTIONS':\n\t\tcase 'FINISH_RESOLUTIONS': {\n\t\t\tconst isStarting = action.type === 'START_RESOLUTIONS';\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tfor ( const resolutionArgs of action.args ) {\n\t\t\t\tnextState.set(\n\t\t\t\t\tselectorArgsToStateKey( resolutionArgs ),\n\t\t\t\t\tisStarting\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'INVALIDATE_RESOLUTION': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tnextState.delete( selectorArgsToStateKey( action.args ) );\n\t\t\treturn nextState;\n\t\t}\n\t}\n\treturn state;\n} );\n\n/**\n * Reducer function returning next state for selector resolution, object form:\n *\n * selectorName -> EquivalentKeyMap<Array, boolean>\n *\n * @param state Current state.\n * @param action Dispatched action.\n *\n * @return Next state.\n */\nconst isResolved = ( state: Record< string, State > = {}, action: Action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'INVALIDATE_RESOLUTION_FOR_STORE':\n\t\t\treturn {};\n\t\tcase 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR':\n\t\t\treturn has( state, [ action.selectorName ] )\n\t\t\t\t? omit( state, [ action.selectorName ] )\n\t\t\t\t: state;\n\t\tcase 'START_RESOLUTION':\n\t\tcase 'FINISH_RESOLUTION':\n\t\tcase 'START_RESOLUTIONS':\n\t\tcase 'FINISH_RESOLUTIONS':\n\t\tcase 'INVALIDATE_RESOLUTION':\n\t\t\treturn subKeysIsResolved( state, action );\n\t}\n\treturn state;\n};\n\nexport default isResolved;\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/redux-store/metadata/reducer.ts"],"names":["subKeysIsResolved","state","EquivalentKeyMap","action","type","nextState","set","args","status","error","resolutionArgs","forEach","idx","resolutionState","undefined","errors","delete","isResolved","selectorName"],"mappings":";;;;;;;;;AAGA;;AACA;;AAMA;;AAV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BE,MAAoB;;AAC7E,UAASA,MAAM,CAACC,IAAhB;AACC,SAAK,iCAAL;AACC,aAAO,EAAP;;AACD,SAAK,0CAAL;AACC,aAAO,iBAAKH,KAAL,EAAY,CAAEE,MAAM,CAACe,YAAT,CAAZ,IACJ,kBAAMjB,KAAN,EAAa,CAAEE,MAAM,CAACe,YAAT,CAAb,CADI,GAEJjB,KAFH;;AAGD,SAAK,kBAAL;AACA,SAAK,mBAAL;AACA,SAAK,iBAAL;AACA,SAAK,mBAAL;AACA,SAAK,oBAAL;AACA,SAAK,kBAAL;AACA,SAAK,uBAAL;AACC,aAAOD,iBAAiB,CAAEC,KAAF,EAASE,MAAT,CAAxB;AAdF;;AAgBA,SAAOF,KAAP;AACA,CAlBD;;eAoBegB,U","sourcesContent":["/**\n * External dependencies\n */\nimport { omit, has } from 'lodash';\nimport EquivalentKeyMap from 'equivalent-key-map';\nimport type { Reducer } from 'redux';\n\n/**\n * Internal dependencies\n */\nimport { selectorArgsToStateKey, onSubKey } from './utils';\n\ntype Action =\n\t| ReturnType< typeof import('./actions').startResolution >\n\t| ReturnType< typeof import('./actions').finishResolution >\n\t| ReturnType< typeof import('./actions').failResolution >\n\t| ReturnType< typeof import('./actions').startResolutions >\n\t| ReturnType< typeof import('./actions').finishResolutions >\n\t| ReturnType< typeof import('./actions').failResolutions >\n\t| ReturnType< typeof import('./actions').invalidateResolution >\n\t| ReturnType< typeof import('./actions').invalidateResolutionForStore >\n\t| ReturnType<\n\t\t\ttypeof import('./actions').invalidateResolutionForStoreSelector\n\t >;\n\ntype StateKey = unknown[] | unknown;\nexport type StateValue =\n\t| { status: 'resolving' | 'finished' }\n\t| { status: 'error'; error: Error | unknown };\n\nexport type Status = StateValue[ 'status' ];\nexport type State = EquivalentKeyMap< StateKey, StateValue >;\n\n/**\n * Reducer function returning next state for selector resolution of\n * subkeys, object form:\n *\n * selectorName -> EquivalentKeyMap<Array,boolean>\n */\nconst subKeysIsResolved: Reducer< Record< string, State >, Action > = onSubKey<\n\tState,\n\tAction\n>( 'selectorName' )( ( state = new EquivalentKeyMap(), action: Action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'START_RESOLUTION': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tnextState.set( selectorArgsToStateKey( action.args ), {\n\t\t\t\tstatus: 'resolving',\n\t\t\t} );\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'FINISH_RESOLUTION': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tnextState.set( selectorArgsToStateKey( action.args ), {\n\t\t\t\tstatus: 'finished',\n\t\t\t} );\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'FAIL_RESOLUTION': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tnextState.set( selectorArgsToStateKey( action.args ), {\n\t\t\t\tstatus: 'error',\n\t\t\t\terror: action.error,\n\t\t\t} );\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'START_RESOLUTIONS': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tfor ( const resolutionArgs of action.args ) {\n\t\t\t\tnextState.set( selectorArgsToStateKey( resolutionArgs ), {\n\t\t\t\t\tstatus: 'resolving',\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'FINISH_RESOLUTIONS': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tfor ( const resolutionArgs of action.args ) {\n\t\t\t\tnextState.set( selectorArgsToStateKey( resolutionArgs ), {\n\t\t\t\t\tstatus: 'finished',\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'FAIL_RESOLUTIONS': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\taction.args.forEach( ( resolutionArgs, idx ) => {\n\t\t\t\tconst resolutionState: StateValue = {\n\t\t\t\t\tstatus: 'error',\n\t\t\t\t\terror: undefined,\n\t\t\t\t};\n\n\t\t\t\tconst error = action.errors[ idx ];\n\t\t\t\tif ( error ) {\n\t\t\t\t\tresolutionState.error = error;\n\t\t\t\t}\n\n\t\t\t\tnextState.set(\n\t\t\t\t\tselectorArgsToStateKey( resolutionArgs as unknown[] ),\n\t\t\t\t\tresolutionState\n\t\t\t\t);\n\t\t\t} );\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'INVALIDATE_RESOLUTION': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tnextState.delete( selectorArgsToStateKey( action.args ) );\n\t\t\treturn nextState;\n\t\t}\n\t}\n\treturn state;\n} );\n\n/**\n * Reducer function returning next state for selector resolution, object form:\n *\n * selectorName -> EquivalentKeyMap<Array, boolean>\n *\n * @param state Current state.\n * @param action Dispatched action.\n *\n * @return Next state.\n */\nconst isResolved = ( state: Record< string, State > = {}, action: Action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'INVALIDATE_RESOLUTION_FOR_STORE':\n\t\t\treturn {};\n\t\tcase 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR':\n\t\t\treturn has( state, [ action.selectorName ] )\n\t\t\t\t? omit( state, [ action.selectorName ] )\n\t\t\t\t: state;\n\t\tcase 'START_RESOLUTION':\n\t\tcase 'FINISH_RESOLUTION':\n\t\tcase 'FAIL_RESOLUTION':\n\t\tcase 'START_RESOLUTIONS':\n\t\tcase 'FINISH_RESOLUTIONS':\n\t\tcase 'FAIL_RESOLUTIONS':\n\t\tcase 'INVALIDATE_RESOLUTION':\n\t\t\treturn subKeysIsResolved( state, action );\n\t}\n\treturn state;\n};\n\nexport default isResolved;\n"]}
@@ -5,7 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getCachedResolvers = getCachedResolvers;
7
7
  exports.getIsResolving = getIsResolving;
8
+ exports.getResolutionError = getResolutionError;
9
+ exports.getResolutionState = getResolutionState;
8
10
  exports.hasFinishedResolution = hasFinishedResolution;
11
+ exports.hasResolutionFailed = hasResolutionFailed;
9
12
  exports.hasStartedResolution = hasStartedResolution;
10
13
  exports.isResolving = isResolving;
11
14
 
@@ -23,8 +26,12 @@ var _utils = require("./utils");
23
26
 
24
27
  /** @typedef {Record<string, import('./reducer').State>} State */
25
28
 
29
+ /** @typedef {import('./reducer').StateValue} StateValue */
30
+
31
+ /** @typedef {import('./reducer').Status} Status */
32
+
26
33
  /**
27
- * Returns the raw `isResolving` value for a given selector name,
34
+ * Returns the raw resolution state value for a given selector name,
28
35
  * and arguments set. May be undefined if the selector has never been resolved
29
36
  * or not resolved for the given set of arguments, otherwise true or false for
30
37
  * resolution started and completed respectively.
@@ -33,17 +40,35 @@ var _utils = require("./utils");
33
40
  * @param {string} selectorName Selector name.
34
41
  * @param {unknown[]?} args Arguments passed to selector.
35
42
  *
36
- * @return {boolean | undefined} isResolving value.
43
+ * @return {StateValue|undefined} isResolving value.
37
44
  */
38
- function getIsResolving(state, selectorName, args) {
45
+ function getResolutionState(state, selectorName, args) {
39
46
  const map = (0, _lodash.get)(state, [selectorName]);
40
47
 
41
48
  if (!map) {
42
- return undefined;
49
+ return;
43
50
  }
44
51
 
45
52
  return map.get((0, _utils.selectorArgsToStateKey)(args));
46
53
  }
54
+ /**
55
+ * Returns the raw `isResolving` value for a given selector name,
56
+ * and arguments set. May be undefined if the selector has never been resolved
57
+ * or not resolved for the given set of arguments, otherwise true or false for
58
+ * resolution started and completed respectively.
59
+ *
60
+ * @param {State} state Data state.
61
+ * @param {string} selectorName Selector name.
62
+ * @param {unknown[]?} args Arguments passed to selector.
63
+ *
64
+ * @return {boolean | undefined} isResolving value.
65
+ */
66
+
67
+
68
+ function getIsResolving(state, selectorName, args) {
69
+ const resolutionState = getResolutionState(state, selectorName, args);
70
+ return resolutionState && resolutionState.status === 'resolving';
71
+ }
47
72
  /**
48
73
  * Returns true if resolution has already been triggered for a given
49
74
  * selector name, and arguments set.
@@ -57,7 +82,7 @@ function getIsResolving(state, selectorName, args) {
57
82
 
58
83
 
59
84
  function hasStartedResolution(state, selectorName, args) {
60
- return getIsResolving(state, selectorName, args) !== undefined;
85
+ return getResolutionState(state, selectorName, args) !== undefined;
61
86
  }
62
87
  /**
63
88
  * Returns true if resolution has completed for a given selector
@@ -72,7 +97,44 @@ function hasStartedResolution(state, selectorName, args) {
72
97
 
73
98
 
74
99
  function hasFinishedResolution(state, selectorName, args) {
75
- return getIsResolving(state, selectorName, args) === false;
100
+ var _getResolutionState;
101
+
102
+ const status = (_getResolutionState = getResolutionState(state, selectorName, args)) === null || _getResolutionState === void 0 ? void 0 : _getResolutionState.status;
103
+ return status === 'finished' || status === 'error';
104
+ }
105
+ /**
106
+ * Returns true if resolution has failed for a given selector
107
+ * name, and arguments set.
108
+ *
109
+ * @param {State} state Data state.
110
+ * @param {string} selectorName Selector name.
111
+ * @param {unknown[]?} args Arguments passed to selector.
112
+ *
113
+ * @return {boolean} Has resolution failed
114
+ */
115
+
116
+
117
+ function hasResolutionFailed(state, selectorName, args) {
118
+ var _getResolutionState2;
119
+
120
+ return ((_getResolutionState2 = getResolutionState(state, selectorName, args)) === null || _getResolutionState2 === void 0 ? void 0 : _getResolutionState2.status) === 'error';
121
+ }
122
+ /**
123
+ * Returns the resolution error for a given selector name, and arguments set.
124
+ * Note it may be of an Error type, but may also be null, undefined, or anything else
125
+ * that can be `throw`-n.
126
+ *
127
+ * @param {State} state Data state.
128
+ * @param {string} selectorName Selector name.
129
+ * @param {unknown[]?} args Arguments passed to selector.
130
+ *
131
+ * @return {Error|unknown} Last resolution error
132
+ */
133
+
134
+
135
+ function getResolutionError(state, selectorName, args) {
136
+ const resolutionState = getResolutionState(state, selectorName, args);
137
+ return (resolutionState === null || resolutionState === void 0 ? void 0 : resolutionState.status) === 'error' ? resolutionState.error : null;
76
138
  }
77
139
  /**
78
140
  * Returns true if resolution has been triggered but has not yet completed for
@@ -87,7 +149,9 @@ function hasFinishedResolution(state, selectorName, args) {
87
149
 
88
150
 
89
151
  function isResolving(state, selectorName, args) {
90
- return getIsResolving(state, selectorName, args) === true;
152
+ var _getResolutionState3;
153
+
154
+ return ((_getResolutionState3 = getResolutionState(state, selectorName, args)) === null || _getResolutionState3 === void 0 ? void 0 : _getResolutionState3.status) === 'resolving';
91
155
  }
92
156
  /**
93
157
  * Returns the list of the cached resolvers.
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/redux-store/metadata/selectors.js"],"names":["getIsResolving","state","selectorName","args","map","undefined","get","hasStartedResolution","hasFinishedResolution","isResolving","getCachedResolvers"],"mappings":";;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,cAAT,CAAyBC,KAAzB,EAAgCC,YAAhC,EAA8CC,IAA9C,EAAqD;AAC3D,QAAMC,GAAG,GAAG,iBAAKH,KAAL,EAAY,CAAEC,YAAF,CAAZ,CAAZ;;AACA,MAAK,CAAEE,GAAP,EAAa;AACZ,WAAOC,SAAP;AACA;;AAED,SAAOD,GAAG,CAACE,GAAJ,CAAS,mCAAwBH,IAAxB,CAAT,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,oBAAT,CAA+BN,KAA/B,EAAsCC,YAAtC,EAAoDC,IAApD,EAA2D;AACjE,SAAOH,cAAc,CAAEC,KAAF,EAASC,YAAT,EAAuBC,IAAvB,CAAd,KAAgDE,SAAvD;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,qBAAT,CAAgCP,KAAhC,EAAuCC,YAAvC,EAAqDC,IAArD,EAA4D;AAClE,SAAOH,cAAc,CAAEC,KAAF,EAASC,YAAT,EAAuBC,IAAvB,CAAd,KAAgD,KAAvD;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASM,WAAT,CAAsBR,KAAtB,EAA6BC,YAA7B,EAA2CC,IAA3C,EAAkD;AACxD,SAAOH,cAAc,CAAEC,KAAF,EAASC,YAAT,EAAuBC,IAAvB,CAAd,KAAgD,IAAvD;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASO,kBAAT,CAA6BT,KAA7B,EAAqC;AAC3C,SAAOA,KAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport { selectorArgsToStateKey } from './utils';\n\n/** @typedef {Record<string, import('./reducer').State>} State */\n\n/**\n * Returns the raw `isResolving` value for a given selector name,\n * and arguments set. May be undefined if the selector has never been resolved\n * or not resolved for the given set of arguments, otherwise true or false for\n * resolution started and completed respectively.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean | undefined} isResolving value.\n */\nexport function getIsResolving( state, selectorName, args ) {\n\tconst map = get( state, [ selectorName ] );\n\tif ( ! map ) {\n\t\treturn undefined;\n\t}\n\n\treturn map.get( selectorArgsToStateKey( args ) );\n}\n\n/**\n * Returns true if resolution has already been triggered for a given\n * selector name, and arguments set.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution has been triggered.\n */\nexport function hasStartedResolution( state, selectorName, args ) {\n\treturn getIsResolving( state, selectorName, args ) !== undefined;\n}\n\n/**\n * Returns true if resolution has completed for a given selector\n * name, and arguments set.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution has completed.\n */\nexport function hasFinishedResolution( state, selectorName, args ) {\n\treturn getIsResolving( state, selectorName, args ) === false;\n}\n\n/**\n * Returns true if resolution has been triggered but has not yet completed for\n * a given selector name, and arguments set.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution is in progress.\n */\nexport function isResolving( state, selectorName, args ) {\n\treturn getIsResolving( state, selectorName, args ) === true;\n}\n\n/**\n * Returns the list of the cached resolvers.\n *\n * @param {State} state Data state.\n *\n * @return {State} Resolvers mapped by args and selectorName.\n */\nexport function getCachedResolvers( state ) {\n\treturn state;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/redux-store/metadata/selectors.js"],"names":["getResolutionState","state","selectorName","args","map","get","getIsResolving","resolutionState","status","hasStartedResolution","undefined","hasFinishedResolution","hasResolutionFailed","getResolutionError","error","isResolving","getCachedResolvers"],"mappings":";;;;;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;;AACA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,kBAAT,CAA6BC,KAA7B,EAAoCC,YAApC,EAAkDC,IAAlD,EAAyD;AAC/D,QAAMC,GAAG,GAAG,iBAAKH,KAAL,EAAY,CAAEC,YAAF,CAAZ,CAAZ;;AACA,MAAK,CAAEE,GAAP,EAAa;AACZ;AACA;;AAED,SAAOA,GAAG,CAACC,GAAJ,CAAS,mCAAwBF,IAAxB,CAAT,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,cAAT,CAAyBL,KAAzB,EAAgCC,YAAhC,EAA8CC,IAA9C,EAAqD;AAC3D,QAAMI,eAAe,GAAGP,kBAAkB,CAAEC,KAAF,EAASC,YAAT,EAAuBC,IAAvB,CAA1C;AAEA,SAAOI,eAAe,IAAIA,eAAe,CAACC,MAAhB,KAA2B,WAArD;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,oBAAT,CAA+BR,KAA/B,EAAsCC,YAAtC,EAAoDC,IAApD,EAA2D;AACjE,SAAOH,kBAAkB,CAAEC,KAAF,EAASC,YAAT,EAAuBC,IAAvB,CAAlB,KAA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C,SAAOA,KAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport { selectorArgsToStateKey } from './utils';\n\n/** @typedef {Record<string, import('./reducer').State>} State */\n/** @typedef {import('./reducer').StateValue} StateValue */\n/** @typedef {import('./reducer').Status} Status */\n\n/**\n * Returns the raw resolution state value for a given selector name,\n * and arguments set. May be undefined if the selector has never been resolved\n * or not resolved for the given set of arguments, otherwise true or false for\n * resolution started and completed respectively.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {StateValue|undefined} isResolving value.\n */\nexport function getResolutionState( state, selectorName, args ) {\n\tconst map = get( state, [ selectorName ] );\n\tif ( ! map ) {\n\t\treturn;\n\t}\n\n\treturn map.get( selectorArgsToStateKey( args ) );\n}\n\n/**\n * Returns the raw `isResolving` value for a given selector name,\n * and arguments set. May be undefined if the selector has never been resolved\n * or not resolved for the given set of arguments, otherwise true or false for\n * resolution started and completed respectively.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean | undefined} isResolving value.\n */\nexport function getIsResolving( state, selectorName, args ) {\n\tconst resolutionState = getResolutionState( state, selectorName, args );\n\n\treturn resolutionState && resolutionState.status === 'resolving';\n}\n\n/**\n * Returns true if resolution has already been triggered for a given\n * selector name, and arguments set.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution has been triggered.\n */\nexport function hasStartedResolution( state, selectorName, args ) {\n\treturn getResolutionState( state, selectorName, args ) !== undefined;\n}\n\n/**\n * Returns true if resolution has completed for a given selector\n * name, and arguments set.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution has completed.\n */\nexport function hasFinishedResolution( state, selectorName, args ) {\n\tconst status = getResolutionState( state, selectorName, args )?.status;\n\treturn status === 'finished' || status === 'error';\n}\n\n/**\n * Returns true if resolution has failed for a given selector\n * name, and arguments set.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Has resolution failed\n */\nexport function hasResolutionFailed( state, selectorName, args ) {\n\treturn getResolutionState( state, selectorName, args )?.status === 'error';\n}\n\n/**\n * Returns the resolution error for a given selector name, and arguments set.\n * Note it may be of an Error type, but may also be null, undefined, or anything else\n * that can be `throw`-n.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {Error|unknown} Last resolution error\n */\nexport function getResolutionError( state, selectorName, args ) {\n\tconst resolutionState = getResolutionState( state, selectorName, args );\n\treturn resolutionState?.status === 'error' ? resolutionState.error : null;\n}\n\n/**\n * Returns true if resolution has been triggered but has not yet completed for\n * a given selector name, and arguments set.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution is in progress.\n */\nexport function isResolving( state, selectorName, args ) {\n\treturn (\n\t\tgetResolutionState( state, selectorName, args )?.status === 'resolving'\n\t);\n}\n\n/**\n * Returns the list of the cached resolvers.\n *\n * @param {State} state Data state.\n *\n * @return {State} Resolvers mapped by args and selectorName.\n */\nexport function getCachedResolvers( state ) {\n\treturn state;\n}\n"]}
package/build/registry.js CHANGED
@@ -172,7 +172,6 @@ function createRegistry() {
172
172
  } //
173
173
  // Deprecated
174
174
  // TODO: Remove this after `use()` is removed.
175
- //
176
175
 
177
176
 
178
177
  function withPlugins(attributes) {
@@ -320,7 +319,6 @@ function createRegistry() {
320
319
  }; //
321
320
  // TODO:
322
321
  // This function will be deprecated as soon as it is no longer internally referenced.
323
- //
324
322
 
325
323
  function use(plugin, options) {
326
324
  if (!plugin) {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/registry.js"],"names":["createRegistry","storeConfigs","parent","stores","emitter","__experimentalListeningStores","Set","globalListener","emit","subscribe","listener","select","storeNameOrDescriptor","storeName","name","add","store","getSelectors","__experimentalMarkListeningStores","callback","ref","clear","result","call","current","Array","from","resolveSelect","getResolveSelectors","dispatch","getActions","withPlugins","attributes","attribute","key","registry","apply","arguments","registerStoreInstance","TypeError","currentSubscribe","unsubscribeFromEmitter","unsubscribeFromStore","isPaused","register","instantiate","registerGenericStore","since","alternative","registerStore","options","reducer","__experimentalSubscribeStore","handler","batch","pause","resume","namespaces","use","plugin","coreDataStore","config","Object","entries"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAKA;;AACA;;AACA;;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,cAAT,GAA4D;AAAA,MAAnCC,YAAmC,uEAApB,EAAoB;AAAA,MAAhBC,MAAgB,uEAAP,IAAO;AAClE,QAAMC,MAAM,GAAG,EAAf;AACA,QAAMC,OAAO,GAAG,6BAAhB;;AACA,QAAMC,6BAA6B,GAAG,IAAIC,GAAJ,EAAtC;AAEA;AACD;AACA;;;AACC,WAASC,cAAT,GAA0B;AACzBH,IAAAA,OAAO,CAACI,IAAR;AACA;AAED;AACD;AACA;AACA;AACA;AACA;AACA;;;AACC,QAAMC,SAAS,GAAKC,QAAF,IAAgB;AACjC,WAAON,OAAO,CAACK,SAAR,CAAmBC,QAAnB,CAAP;AACA,GAFD;AAIA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;;;AACC,WAASC,MAAT,CAAiBC,qBAAjB,EAAyC;AACxC,UAAMC,SAAS,GAAG,sBAAUD,qBAAV,IACfA,qBAAqB,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AP;AACA;;AAEDA,EAAAA,QAAQ,CAACS,QAAT,CAAmBgB,cAAnB;;AAEA,OAAM,MAAM,CAAE9C,IAAF,EAAQ+C,MAAR,CAAZ,IAAgCC,MAAM,CAACC,OAAP,CAAgB9D,YAAhB,CAAhC,EAAiE;AAChEkC,IAAAA,QAAQ,CAACS,QAAT,CAAmB,yBAAkB9B,IAAlB,EAAwB+C,MAAxB,CAAnB;AACA;;AAED,MAAK3D,MAAL,EAAc;AACbA,IAAAA,MAAM,CAACO,SAAP,CAAkBF,cAAlB;AACA;;AAED,SAAOwB,WAAW,CAAEI,QAAF,CAAlB;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { mapValues, isObject, forEach } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport createReduxStore from './redux-store';\nimport coreDataStore from './store';\nimport { createEmitter } from './utils/emitter';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\n/**\n * @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations.\n *\n * @property {Function} registerGenericStore Given a namespace key and settings\n * object, registers a new generic\n * store.\n * @property {Function} registerStore Given a namespace key and settings\n * object, registers a new namespace\n * store.\n * @property {Function} subscribe Given a function callback, invokes\n * the callback on any change to state\n * within any registered store.\n * @property {Function} select Given a namespace key, returns an\n * object of the store's registered\n * selectors.\n * @property {Function} dispatch Given a namespace key, returns an\n * object of the store's registered\n * action dispatchers.\n */\n\n/**\n * @typedef {Object} WPDataPlugin An object of registry function overrides.\n *\n * @property {Function} registerStore registers store.\n */\n\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param {Object} storeConfigs Initial store configurations.\n * @param {Object?} parent Parent registry.\n *\n * @return {WPDataRegistry} Data registry.\n */\nexport function createRegistry( storeConfigs = {}, parent = null ) {\n\tconst stores = {};\n\tconst emitter = createEmitter();\n\tconst __experimentalListeningStores = new Set();\n\n\t/**\n\t * Global listener called for each store's update.\n\t */\n\tfunction globalListener() {\n\t\temitter.emit();\n\t}\n\n\t/**\n\t * Subscribe to changes to any data.\n\t *\n\t * @param {Function} listener Listener function.\n\t *\n\t * @return {Function} Unsubscribe function.\n\t */\n\tconst subscribe = ( listener ) => {\n\t\treturn emitter.subscribe( listener );\n\t};\n\n\t/**\n\t * Calls a selector given the current state and extra arguments.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {*} The selector's returned value.\n\t */\n\tfunction select( storeNameOrDescriptor ) {\n\t\tconst storeName = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor;\n\t\t__experimentalListeningStores.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSelectors();\n\t\t}\n\n\t\treturn parent && parent.select( storeName );\n\t}\n\n\tfunction __experimentalMarkListeningStores( callback, ref ) {\n\t\t__experimentalListeningStores.clear();\n\t\tconst result = callback.call( this );\n\t\tref.current = Array.from( __experimentalListeningStores );\n\t\treturn result;\n\t}\n\n\t/**\n\t * Given the name of a registered store, returns an object containing the store's\n\t * selectors pre-bound to state so that you only need to supply additional arguments,\n\t * and modified so that they return promises that resolve to their eventual values,\n\t * after any resolvers have ran.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {Object} Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor;\n\t\t__experimentalListeningStores.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getResolveSelectors();\n\t\t}\n\n\t\treturn parent && parent.resolveSelect( storeName );\n\t}\n\n\t/**\n\t * Returns the available actions for a part of the state.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {*} The action's returned value.\n\t */\n\tfunction dispatch( storeNameOrDescriptor ) {\n\t\tconst storeName = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor;\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getActions();\n\t\t}\n\n\t\treturn parent && parent.dispatch( storeName );\n\t}\n\n\t//\n\t// Deprecated\n\t// TODO: Remove this after `use()` is removed.\n\t//\n\tfunction withPlugins( attributes ) {\n\t\treturn mapValues( attributes, ( attribute, key ) => {\n\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\treturn attribute;\n\t\t\t}\n\t\t\treturn function () {\n\t\t\t\treturn registry[ key ].apply( null, arguments );\n\t\t\t};\n\t\t} );\n\t}\n\n\t/**\n\t * Registers a store instance.\n\t *\n\t * @param {string} name Store registry name.\n\t * @param {Object} store Store instance object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance( name, store ) {\n\t\tif ( typeof store.getSelectors !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getSelectors must be a function' );\n\t\t}\n\t\tif ( typeof store.getActions !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getActions must be a function' );\n\t\t}\n\t\tif ( typeof store.subscribe !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.subscribe must be a function' );\n\t\t}\n\t\t// The emitter is used to keep track of active listeners when the registry\n\t\t// get paused, that way, when resumed we should be able to call all these\n\t\t// pending listeners.\n\t\tstore.emitter = createEmitter();\n\t\tconst currentSubscribe = store.subscribe;\n\t\tstore.subscribe = ( listener ) => {\n\t\t\tconst unsubscribeFromEmitter = store.emitter.subscribe( listener );\n\t\t\tconst unsubscribeFromStore = currentSubscribe( () => {\n\t\t\t\tif ( store.emitter.isPaused ) {\n\t\t\t\t\tstore.emitter.emit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlistener();\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tunsubscribeFromStore?.();\n\t\t\t\tunsubscribeFromEmitter?.();\n\t\t\t};\n\t\t};\n\t\tstores[ name ] = store;\n\t\tstore.subscribe( globalListener );\n\t}\n\n\t/**\n\t * Registers a new store given a store descriptor.\n\t *\n\t * @param {StoreDescriptor} store Store descriptor.\n\t */\n\tfunction register( store ) {\n\t\tregisterStoreInstance( store.name, store.instantiate( registry ) );\n\t}\n\n\tfunction registerGenericStore( name, store ) {\n\t\tdeprecated( 'wp.data.registerGenericStore', {\n\t\t\tsince: '5.9',\n\t\t\talternative: 'wp.data.register( storeDescriptor )',\n\t\t} );\n\t\tregisterStoreInstance( name, store );\n\t}\n\n\t/**\n\t * Registers a standard `@wordpress/data` store.\n\t *\n\t * @param {string} storeName Unique namespace identifier.\n\t * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return {Object} Registered store object.\n\t */\n\tfunction registerStore( storeName, options ) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = createReduxStore( storeName, options ).instantiate(\n\t\t\tregistry\n\t\t);\n\t\tregisterStoreInstance( storeName, store );\n\t\treturn store.store;\n\t}\n\n\t/**\n\t * Subscribe handler to a store.\n\t *\n\t * @param {string[]} storeName The store name.\n\t * @param {Function} handler The function subscribed to the store.\n\t * @return {Function} A function to unsubscribe the handler.\n\t */\n\tfunction __experimentalSubscribeStore( storeName, handler ) {\n\t\tif ( storeName in stores ) {\n\t\t\treturn stores[ storeName ].subscribe( handler );\n\t\t}\n\n\t\t// Trying to access a store that hasn't been registered,\n\t\t// this is a pattern rarely used but seen in some places.\n\t\t// We fallback to regular `subscribe` here for backward-compatibility for now.\n\t\t// See https://github.com/WordPress/gutenberg/pull/27466 for more info.\n\t\tif ( ! parent ) {\n\t\t\treturn subscribe( handler );\n\t\t}\n\n\t\treturn parent.__experimentalSubscribeStore( storeName, handler );\n\t}\n\n\tfunction batch( callback ) {\n\t\temitter.pause();\n\t\tforEach( stores, ( store ) => store.emitter.pause() );\n\t\tcallback();\n\t\temitter.resume();\n\t\tforEach( stores, ( store ) => store.emitter.resume() );\n\t}\n\n\tlet registry = {\n\t\tbatch,\n\t\tstores,\n\t\tnamespaces: stores, // TODO: Deprecate/remove this.\n\t\tsubscribe,\n\t\tselect,\n\t\tresolveSelect,\n\t\tdispatch,\n\t\tuse,\n\t\tregister,\n\t\tregisterGenericStore,\n\t\tregisterStore,\n\t\t__experimentalMarkListeningStores,\n\t\t__experimentalSubscribeStore,\n\t};\n\n\t//\n\t// TODO:\n\t// This function will be deprecated as soon as it is no longer internally referenced.\n\t//\n\tfunction use( plugin, options ) {\n\t\tif ( ! plugin ) {\n\t\t\treturn;\n\t\t}\n\n\t\tregistry = {\n\t\t\t...registry,\n\t\t\t...plugin( registry, options ),\n\t\t};\n\n\t\treturn registry;\n\t}\n\n\tregistry.register( coreDataStore );\n\n\tfor ( const [ name, config ] of Object.entries( storeConfigs ) ) {\n\t\tregistry.register( createReduxStore( name, config ) );\n\t}\n\n\tif ( parent ) {\n\t\tparent.subscribe( globalListener );\n\t}\n\n\treturn withPlugins( registry );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/registry.js"],"names":["createRegistry","storeConfigs","parent","stores","emitter","__experimentalListeningStores","Set","globalListener","emit","subscribe","listener","select","storeNameOrDescriptor","storeName","name","add","store","getSelectors","__experimentalMarkListeningStores","callback","ref","clear","result","call","current","Array","from","resolveSelect","getResolveSelectors","dispatch","getActions","withPlugins","attributes","attribute","key","registry","apply","arguments","registerStoreInstance","TypeError","currentSubscribe","unsubscribeFromEmitter","unsubscribeFromStore","isPaused","register","instantiate","registerGenericStore","since","alternative","registerStore","options","reducer","__experimentalSubscribeStore","handler","batch","pause","resume","namespaces","use","plugin","coreDataStore","config","Object","entries"],"mappings":";;;;;;;;;AAGA;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, forEach } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport createReduxStore from './redux-store';\nimport coreDataStore from './store';\nimport { createEmitter } from './utils/emitter';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\n/**\n * @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations.\n *\n * @property {Function} registerGenericStore Given a namespace key and settings\n * object, registers a new generic\n * store.\n * @property {Function} registerStore Given a namespace key and settings\n * object, registers a new namespace\n * store.\n * @property {Function} subscribe Given a function callback, invokes\n * the callback on any change to state\n * within any registered store.\n * @property {Function} select Given a namespace key, returns an\n * object of the store's registered\n * selectors.\n * @property {Function} dispatch Given a namespace key, returns an\n * object of the store's registered\n * action dispatchers.\n */\n\n/**\n * @typedef {Object} WPDataPlugin An object of registry function overrides.\n *\n * @property {Function} registerStore registers store.\n */\n\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param {Object} storeConfigs Initial store configurations.\n * @param {Object?} parent Parent registry.\n *\n * @return {WPDataRegistry} Data registry.\n */\nexport function createRegistry( storeConfigs = {}, parent = null ) {\n\tconst stores = {};\n\tconst emitter = createEmitter();\n\tconst __experimentalListeningStores = new Set();\n\n\t/**\n\t * Global listener called for each store's update.\n\t */\n\tfunction globalListener() {\n\t\temitter.emit();\n\t}\n\n\t/**\n\t * Subscribe to changes to any data.\n\t *\n\t * @param {Function} listener Listener function.\n\t *\n\t * @return {Function} Unsubscribe function.\n\t */\n\tconst subscribe = ( listener ) => {\n\t\treturn emitter.subscribe( listener );\n\t};\n\n\t/**\n\t * Calls a selector given the current state and extra arguments.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {*} The selector's returned value.\n\t */\n\tfunction select( storeNameOrDescriptor ) {\n\t\tconst storeName = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor;\n\t\t__experimentalListeningStores.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSelectors();\n\t\t}\n\n\t\treturn parent && parent.select( storeName );\n\t}\n\n\tfunction __experimentalMarkListeningStores( callback, ref ) {\n\t\t__experimentalListeningStores.clear();\n\t\tconst result = callback.call( this );\n\t\tref.current = Array.from( __experimentalListeningStores );\n\t\treturn result;\n\t}\n\n\t/**\n\t * Given the name of a registered store, returns an object containing the store's\n\t * selectors pre-bound to state so that you only need to supply additional arguments,\n\t * and modified so that they return promises that resolve to their eventual values,\n\t * after any resolvers have ran.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {Object} Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor;\n\t\t__experimentalListeningStores.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getResolveSelectors();\n\t\t}\n\n\t\treturn parent && parent.resolveSelect( storeName );\n\t}\n\n\t/**\n\t * Returns the available actions for a part of the state.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {*} The action's returned value.\n\t */\n\tfunction dispatch( storeNameOrDescriptor ) {\n\t\tconst storeName = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor;\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getActions();\n\t\t}\n\n\t\treturn parent && parent.dispatch( storeName );\n\t}\n\n\t//\n\t// Deprecated\n\t// TODO: Remove this after `use()` is removed.\n\tfunction withPlugins( attributes ) {\n\t\treturn mapValues( attributes, ( attribute, key ) => {\n\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\treturn attribute;\n\t\t\t}\n\t\t\treturn function () {\n\t\t\t\treturn registry[ key ].apply( null, arguments );\n\t\t\t};\n\t\t} );\n\t}\n\n\t/**\n\t * Registers a store instance.\n\t *\n\t * @param {string} name Store registry name.\n\t * @param {Object} store Store instance object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance( name, store ) {\n\t\tif ( typeof store.getSelectors !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getSelectors must be a function' );\n\t\t}\n\t\tif ( typeof store.getActions !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getActions must be a function' );\n\t\t}\n\t\tif ( typeof store.subscribe !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.subscribe must be a function' );\n\t\t}\n\t\t// The emitter is used to keep track of active listeners when the registry\n\t\t// get paused, that way, when resumed we should be able to call all these\n\t\t// pending listeners.\n\t\tstore.emitter = createEmitter();\n\t\tconst currentSubscribe = store.subscribe;\n\t\tstore.subscribe = ( listener ) => {\n\t\t\tconst unsubscribeFromEmitter = store.emitter.subscribe( listener );\n\t\t\tconst unsubscribeFromStore = currentSubscribe( () => {\n\t\t\t\tif ( store.emitter.isPaused ) {\n\t\t\t\t\tstore.emitter.emit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlistener();\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tunsubscribeFromStore?.();\n\t\t\t\tunsubscribeFromEmitter?.();\n\t\t\t};\n\t\t};\n\t\tstores[ name ] = store;\n\t\tstore.subscribe( globalListener );\n\t}\n\n\t/**\n\t * Registers a new store given a store descriptor.\n\t *\n\t * @param {StoreDescriptor} store Store descriptor.\n\t */\n\tfunction register( store ) {\n\t\tregisterStoreInstance( store.name, store.instantiate( registry ) );\n\t}\n\n\tfunction registerGenericStore( name, store ) {\n\t\tdeprecated( 'wp.data.registerGenericStore', {\n\t\t\tsince: '5.9',\n\t\t\talternative: 'wp.data.register( storeDescriptor )',\n\t\t} );\n\t\tregisterStoreInstance( name, store );\n\t}\n\n\t/**\n\t * Registers a standard `@wordpress/data` store.\n\t *\n\t * @param {string} storeName Unique namespace identifier.\n\t * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return {Object} Registered store object.\n\t */\n\tfunction registerStore( storeName, options ) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = createReduxStore( storeName, options ).instantiate(\n\t\t\tregistry\n\t\t);\n\t\tregisterStoreInstance( storeName, store );\n\t\treturn store.store;\n\t}\n\n\t/**\n\t * Subscribe handler to a store.\n\t *\n\t * @param {string[]} storeName The store name.\n\t * @param {Function} handler The function subscribed to the store.\n\t * @return {Function} A function to unsubscribe the handler.\n\t */\n\tfunction __experimentalSubscribeStore( storeName, handler ) {\n\t\tif ( storeName in stores ) {\n\t\t\treturn stores[ storeName ].subscribe( handler );\n\t\t}\n\n\t\t// Trying to access a store that hasn't been registered,\n\t\t// this is a pattern rarely used but seen in some places.\n\t\t// We fallback to regular `subscribe` here for backward-compatibility for now.\n\t\t// See https://github.com/WordPress/gutenberg/pull/27466 for more info.\n\t\tif ( ! parent ) {\n\t\t\treturn subscribe( handler );\n\t\t}\n\n\t\treturn parent.__experimentalSubscribeStore( storeName, handler );\n\t}\n\n\tfunction batch( callback ) {\n\t\temitter.pause();\n\t\tforEach( stores, ( store ) => store.emitter.pause() );\n\t\tcallback();\n\t\temitter.resume();\n\t\tforEach( stores, ( store ) => store.emitter.resume() );\n\t}\n\n\tlet registry = {\n\t\tbatch,\n\t\tstores,\n\t\tnamespaces: stores, // TODO: Deprecate/remove this.\n\t\tsubscribe,\n\t\tselect,\n\t\tresolveSelect,\n\t\tdispatch,\n\t\tuse,\n\t\tregister,\n\t\tregisterGenericStore,\n\t\tregisterStore,\n\t\t__experimentalMarkListeningStores,\n\t\t__experimentalSubscribeStore,\n\t};\n\n\t//\n\t// TODO:\n\t// This function will be deprecated as soon as it is no longer internally referenced.\n\tfunction use( plugin, options ) {\n\t\tif ( ! plugin ) {\n\t\t\treturn;\n\t\t}\n\n\t\tregistry = {\n\t\t\t...registry,\n\t\t\t...plugin( registry, options ),\n\t\t};\n\n\t\treturn registry;\n\t}\n\n\tregistry.register( coreDataStore );\n\n\tfor ( const [ name, config ] of Object.entries( storeConfigs ) ) {\n\t\tregistry.register( createReduxStore( name, config ) );\n\t}\n\n\tif ( parent ) {\n\t\tparent.subscribe( globalListener );\n\t}\n\n\treturn withPlugins( registry );\n}\n"]}
@@ -43,9 +43,9 @@ const createResolversCacheMiddleware = (registry, reducerKey) => () => next => a
43
43
 
44
44
  resolversByArgs.forEach((value, args) => {
45
45
  // resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector.
46
- // If the value is false it means this resolver has finished its resolution which means we need to invalidate it,
47
- // if it's true it means it's inflight and the invalidation is not necessary.
48
- if (value !== false || !resolver.shouldInvalidate(action, ...args)) {
46
+ // If the value is "finished" or "error" it means this resolver has finished its resolution which means we need
47
+ // to invalidate it, if it's true it means it's inflight and the invalidation is not necessary.
48
+ if ((value === null || value === void 0 ? void 0 : value.status) !== 'finished' && (value === null || value === void 0 ? void 0 : value.status) !== 'error' || !resolver.shouldInvalidate(action, ...args)) {
49
49
  return;
50
50
  } // Trigger cache invalidation
51
51
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/resolvers-cache-middleware.js"],"names":["createResolversCacheMiddleware","registry","reducerKey","next","action","resolvers","select","coreDataStore","getCachedResolvers","Object","entries","forEach","selectorName","resolversByArgs","resolver","stores","shouldInvalidate","value","args","dispatch","invalidateResolution"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,8BAA8B,GAAG,CAAEC,QAAF,EAAYC,UAAZ,KAA4B,MAClEC,IADwE,IAElEC,MAAF,IAAc;AAClB,QAAMC,SAAS,GAAGJ,QAAQ,CACxBK,MADgB,CACRC,cADQ,EAEhBC,kBAFgB,CAEIN,UAFJ,CAAlB;AAGAO,EAAAA,MAAM,CAACC,OAAP,CAAgBL,SAAhB,EAA4BM,OAA5B,CACC,QAAyC;AAAA,QAAvC,CAAEC,YAAF,EAAgBC,eAAhB,CAAuC;AACxC,UAAMC,QAAQ,GAAG,iBAAKb,QAAQ,CAACc,MAAd,EAAsB,CACtCb,UADsC,EAEtC,WAFsC,EAGtCU,YAHsC,CAAtB,CAAjB;;AAKA,QAAK,CAAEE,QAAF,IAAc,CAAEA,QAAQ,CAACE,gBAA9B,EAAiD;AAChD;AACA;;AACDH,IAAAA,eAAe,CAACF,OAAhB,CAAyB,CAAEM,KAAF,EAASC,IAAT,KAAmB;AAC3C;AACA;AACA;AACA,UACCD,KAAK,KAAK,KAAV,IACA,CAAEH,QAAQ,CAACE,gBAAT,CAA2BZ,MAA3B,EAAmC,GAAGc,IAAtC,CAFH,EAGE;AACD;AACA,OAT0C,CAW3C;;;AACAjB,MAAAA,QAAQ,CACNkB,QADF,CACYZ,cADZ,EAEEa,oBAFF,CAEwBlB,UAFxB,EAEoCU,YAFpC,EAEkDM,IAFlD;AAGA,KAfD;AAgBA,GA1BF;AA4BA,SAAOf,IAAI,CAAEC,MAAF,CAAX;AACA,CAnCD;;eAqCeJ,8B","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport coreDataStore from './store';\n\n/** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */\n\n/**\n * Creates a middleware handling resolvers cache invalidation.\n *\n * @param {WPDataRegistry} registry The registry reference for which to create\n * the middleware.\n * @param {string} reducerKey The namespace for which to create the\n * middleware.\n *\n * @return {Function} Middleware function.\n */\nconst createResolversCacheMiddleware = ( registry, reducerKey ) => () => (\n\tnext\n) => ( action ) => {\n\tconst resolvers = registry\n\t\t.select( coreDataStore )\n\t\t.getCachedResolvers( reducerKey );\n\tObject.entries( resolvers ).forEach(\n\t\t( [ selectorName, resolversByArgs ] ) => {\n\t\t\tconst resolver = get( registry.stores, [\n\t\t\t\treducerKey,\n\t\t\t\t'resolvers',\n\t\t\t\tselectorName,\n\t\t\t] );\n\t\t\tif ( ! resolver || ! resolver.shouldInvalidate ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolversByArgs.forEach( ( value, args ) => {\n\t\t\t\t// resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector.\n\t\t\t\t// If the value is false it means this resolver has finished its resolution which means we need to invalidate it,\n\t\t\t\t// if it's true it means it's inflight and the invalidation is not necessary.\n\t\t\t\tif (\n\t\t\t\t\tvalue !== false ||\n\t\t\t\t\t! resolver.shouldInvalidate( action, ...args )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Trigger cache invalidation\n\t\t\t\tregistry\n\t\t\t\t\t.dispatch( coreDataStore )\n\t\t\t\t\t.invalidateResolution( reducerKey, selectorName, args );\n\t\t\t} );\n\t\t}\n\t);\n\treturn next( action );\n};\n\nexport default createResolversCacheMiddleware;\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/resolvers-cache-middleware.js"],"names":["createResolversCacheMiddleware","registry","reducerKey","next","action","resolvers","select","coreDataStore","getCachedResolvers","Object","entries","forEach","selectorName","resolversByArgs","resolver","stores","shouldInvalidate","value","args","status","dispatch","invalidateResolution"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,8BAA8B,GAAG,CAAEC,QAAF,EAAYC,UAAZ,KAA4B,MAClEC,IADwE,IAElEC,MAAF,IAAc;AAClB,QAAMC,SAAS,GAAGJ,QAAQ,CACxBK,MADgB,CACRC,cADQ,EAEhBC,kBAFgB,CAEIN,UAFJ,CAAlB;AAGAO,EAAAA,MAAM,CAACC,OAAP,CAAgBL,SAAhB,EAA4BM,OAA5B,CACC,QAAyC;AAAA,QAAvC,CAAEC,YAAF,EAAgBC,eAAhB,CAAuC;AACxC,UAAMC,QAAQ,GAAG,iBAAKb,QAAQ,CAACc,MAAd,EAAsB,CACtCb,UADsC,EAEtC,WAFsC,EAGtCU,YAHsC,CAAtB,CAAjB;;AAKA,QAAK,CAAEE,QAAF,IAAc,CAAEA,QAAQ,CAACE,gBAA9B,EAAiD;AAChD;AACA;;AACDH,IAAAA,eAAe,CAACF,OAAhB,CAAyB,CAAEM,KAAF,EAASC,IAAT,KAAmB;AAC3C;AACA;AACA;AACA,UACG,CAAAD,KAAK,SAAL,IAAAA,KAAK,WAAL,YAAAA,KAAK,CAAEE,MAAP,MAAkB,UAAlB,IACD,CAAAF,KAAK,SAAL,IAAAA,KAAK,WAAL,YAAAA,KAAK,CAAEE,MAAP,MAAkB,OADnB,IAEA,CAAEL,QAAQ,CAACE,gBAAT,CAA2BZ,MAA3B,EAAmC,GAAGc,IAAtC,CAHH,EAIE;AACD;AACA,OAV0C,CAY3C;;;AACAjB,MAAAA,QAAQ,CACNmB,QADF,CACYb,cADZ,EAEEc,oBAFF,CAEwBnB,UAFxB,EAEoCU,YAFpC,EAEkDM,IAFlD;AAGA,KAhBD;AAiBA,GA3BF;AA6BA,SAAOf,IAAI,CAAEC,MAAF,CAAX;AACA,CApCD;;eAsCeJ,8B","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport coreDataStore from './store';\n\n/** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */\n\n/**\n * Creates a middleware handling resolvers cache invalidation.\n *\n * @param {WPDataRegistry} registry The registry reference for which to create\n * the middleware.\n * @param {string} reducerKey The namespace for which to create the\n * middleware.\n *\n * @return {Function} Middleware function.\n */\nconst createResolversCacheMiddleware = ( registry, reducerKey ) => () => (\n\tnext\n) => ( action ) => {\n\tconst resolvers = registry\n\t\t.select( coreDataStore )\n\t\t.getCachedResolvers( reducerKey );\n\tObject.entries( resolvers ).forEach(\n\t\t( [ selectorName, resolversByArgs ] ) => {\n\t\t\tconst resolver = get( registry.stores, [\n\t\t\t\treducerKey,\n\t\t\t\t'resolvers',\n\t\t\t\tselectorName,\n\t\t\t] );\n\t\t\tif ( ! resolver || ! resolver.shouldInvalidate ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tresolversByArgs.forEach( ( value, args ) => {\n\t\t\t\t// resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector.\n\t\t\t\t// If the value is \"finished\" or \"error\" it means this resolver has finished its resolution which means we need\n\t\t\t\t// to invalidate it, if it's true it means it's inflight and the invalidation is not necessary.\n\t\t\t\tif (\n\t\t\t\t\t( value?.status !== 'finished' &&\n\t\t\t\t\t\tvalue?.status !== 'error' ) ||\n\t\t\t\t\t! resolver.shouldInvalidate( action, ...args )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Trigger cache invalidation\n\t\t\t\tregistry\n\t\t\t\t\t.dispatch( coreDataStore )\n\t\t\t\t\t.invalidateResolution( reducerKey, selectorName, args );\n\t\t\t} );\n\t\t}\n\t);\n\treturn next( action );\n};\n\nexport default createResolversCacheMiddleware;\n"]}
@@ -194,7 +194,7 @@ export default function useSelect(mapSelect, deps) {
194
194
 
195
195
  forceRender();
196
196
  }
197
- }; // catch any possible state changes during mount before the subscription
197
+ }; // Catch any possible state changes during mount before the subscription
198
198
  // could be set.
199
199
 
200
200
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["useMemoOne","createQueue","useRef","useCallback","useMemo","useReducer","isShallowEqual","useIsomorphicLayoutEffect","useRegistry","useAsyncMode","noop","renderQueue","useSelect","mapSelect","deps","hasMappingFunction","callbackMapper","_mapSelect","registry","isAsync","queueContext","queue","forceRender","s","latestMapSelect","latestIsAsync","latestMapOutput","latestMapOutputError","isMountedAndNotUnsubscribing","listeningStores","trapSelect","callback","__experimentalMarkListeningStores","depsChangedFlag","mapOutput","current","hasReplacedMapSelect","lastMapSelectFailed","select","error","errorMessage","message","stack","console","undefined","flush","onStoreChange","newMapOutput","add","onChange","unsubscribers","map","storeName","__experimentalSubscribeStore","forEach","unsubscribe"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,cAA3B;AAEA;AACA;AACA;;AACA,SAASC,WAAT,QAA4B,2BAA5B;AACA,SAASC,MAAT,EAAiBC,WAAjB,EAA8BC,OAA9B,EAAuCC,UAAvC,QAAyD,oBAAzD;AACA,OAAOC,cAAP,MAA2B,6BAA3B;AACA,SAASC,yBAAT,QAA0C,oBAA1C;AAEA;AACA;AACA;;AACA,OAAOC,WAAP,MAAwB,mCAAxB;AACA,OAAOC,YAAP,MAAyB,uCAAzB;;AAEA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;;AACA,MAAMC,WAAW,GAAGV,WAAW,EAA/B;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASW,SAAT,CAAoBC,SAApB,EAA+BC,IAA/B,EAAsC;AACpD,QAAMC,kBAAkB,GAAG,eAAe,OAAOF,SAAjD,CADoD,CAGpD;AACA;AACA;;AACA,MAAK,CAAEE,kBAAP,EAA4B;AAC3BD,IAAAA,IAAI,GAAG,EAAP;AACA,GARmD,CAUpD;AACA;AACA;AACA;AACA;;;AACA,QAAME,cAAc,GAAGb,W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,kBAAxB,EAA4CkB,eAA5C,CAtDsB,CAAzB;AAwDA,SAAOlB,kBAAkB,GAAGmB,SAAH,GAAehB,QAAQ,CAACoB,MAAT,CAAiBzB,SAAjB,CAAxC;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport { useRef, useCallback, useMemo, useReducer } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst noop = () => {};\nconst renderQueue = createQueue();\n\n/** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://reactjs.org/docs/hooks-rules.html).\n *\n * @param {Function|StoreDescriptor|string} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * implementing this hook. The function receives\n * the `registry.select` method on the first\n * argument and the `registry` on the second\n * argument.\n * When a store key is passed, all selectors for\n * the store will be returned. This is only meant\n * for usage of these selectors in event\n * callbacks, not for data needed to create the\n * element tree.\n * @param {Array} deps If provided, this memoizes the mapSelect so the\n * same `mapSelect` is invoked on every state\n * change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( 'my-shop' ).getPrice( 'hammer', currency )\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( 'my-shop' );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n *\n * @return {Function} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\tconst hasMappingFunction = 'function' === typeof mapSelect;\n\n\t// If we're recalling a store by its name or by\n\t// its descriptor then we won't be caching the\n\t// calls to `mapSelect` because we won't be calling it.\n\tif ( ! hasMappingFunction ) {\n\t\tdeps = [];\n\t}\n\n\t// Because of the \"rule of hooks\" we have to call `useCallback`\n\t// on every invocation whether or not we have a real function\n\t// for `mapSelect`. we'll create this intermediate variable to\n\t// fulfill that need and then reference it with our \"real\"\n\t// `_mapSelect` if we can.\n\tconst callbackMapper = useCallback(\n\t\thasMappingFunction ? mapSelect : noop,\n\t\tdeps\n\t);\n\tconst _mapSelect = hasMappingFunction ? callbackMapper : null;\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\t// React can sometimes clear the `useMemo` cache.\n\t// We use the cache-stable `useMemoOne` to avoid\n\t// losing queues.\n\tconst queueContext = useMemoOne( () => ( { queue: true } ), [ registry ] );\n\tconst [ , forceRender ] = useReducer( ( s ) => s + 1, 0 );\n\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\tconst isMountedAndNotUnsubscribing = useRef();\n\n\t// Keep track of the stores being selected in the _mapSelect function,\n\t// and only subscribe to those stores later.\n\tconst listeningStores = useRef( [] );\n\tconst trapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__experimentalMarkListeningStores(\n\t\t\t\tcallback,\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput;\n\n\tif ( _mapSelect ) {\n\t\tmapOutput = latestMapOutput.current;\n\t\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\t\tconst lastMapSelectFailed = !! latestMapOutputError.current;\n\n\t\tif ( hasReplacedMapSelect || lastMapSelectFailed ) {\n\t\t\ttry {\n\t\t\t\tmapOutput = trapSelect( () =>\n\t\t\t\t\t_mapSelect( registry.select, registry )\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tlet errorMessage = `An error occurred while running 'mapSelect': ${ error.message }`;\n\n\t\t\t\tif ( latestMapOutputError.current ) {\n\t\t\t\t\terrorMessage += `\\nThe error may be correlated with this previous error:\\n`;\n\t\t\t\t\terrorMessage += `${ latestMapOutputError.current.stack }\\n\\n`;\n\t\t\t\t\terrorMessage += 'Original stack trace:';\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.error( errorMessage );\n\t\t\t}\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlatestMapSelect.current = _mapSelect;\n\t\tlatestMapOutput.current = mapOutput;\n\t\tlatestMapOutputError.current = undefined;\n\t\tisMountedAndNotUnsubscribing.current = true;\n\n\t\t// This has to run after the other ref updates\n\t\t// to avoid using stale values in the flushed\n\t\t// callbacks or potentially overwriting a\n\t\t// changed `latestMapOutput.current`.\n\t\tif ( latestIsAsync.current !== isAsync ) {\n\t\t\tlatestIsAsync.current = isAsync;\n\t\t\trenderQueue.flush( queueContext );\n\t\t}\n\t} );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst onStoreChange = () => {\n\t\t\tif ( isMountedAndNotUnsubscribing.current ) {\n\t\t\t\ttry {\n\t\t\t\t\tconst newMapOutput = trapSelect( () =>\n\t\t\t\t\t\tlatestMapSelect.current( registry.select, registry )\n\t\t\t\t\t);\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tisShallowEqual( latestMapOutput.current, newMapOutput )\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t\t}\n\t\t\t\tforceRender();\n\t\t\t}\n\t\t};\n\n\t\t// catch any possible state changes during mount before the subscription\n\t\t// could be set.\n\t\tif ( latestIsAsync.current ) {\n\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t} else {\n\t\t\tonStoreChange();\n\t\t}\n\n\t\tconst onChange = () => {\n\t\t\tif ( latestIsAsync.current ) {\n\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t} else {\n\t\t\t\tonStoreChange();\n\t\t\t}\n\t\t};\n\n\t\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__experimentalSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\treturn () => {\n\t\t\tisMountedAndNotUnsubscribing.current = false;\n\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe?.() );\n\t\t\trenderQueue.flush( queueContext );\n\t\t};\n\t\t// If you're tempted to eliminate the spread dependencies below don't do it!\n\t\t// We're passing these in from the calling function and want to make sure we're\n\t\t// examining every individual value inside the `deps` array.\n\t}, [ registry, trapSelect, hasMappingFunction, depsChangedFlag ] );\n\n\treturn hasMappingFunction ? mapOutput : registry.select( mapSelect );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["useMemoOne","createQueue","useRef","useCallback","useMemo","useReducer","isShallowEqual","useIsomorphicLayoutEffect","useRegistry","useAsyncMode","noop","renderQueue","useSelect","mapSelect","deps","hasMappingFunction","callbackMapper","_mapSelect","registry","isAsync","queueContext","queue","forceRender","s","latestMapSelect","latestIsAsync","latestMapOutput","latestMapOutputError","isMountedAndNotUnsubscribing","listeningStores","trapSelect","callback","__experimentalMarkListeningStores","depsChangedFlag","mapOutput","current","hasReplacedMapSelect","lastMapSelectFailed","select","error","errorMessage","message","stack","console","undefined","flush","onStoreChange","newMapOutput","add","onChange","unsubscribers","map","storeName","__experimentalSubscribeStore","forEach","unsubscribe"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,cAA3B;AAEA;AACA;AACA;;AACA,SAASC,WAAT,QAA4B,2BAA5B;AACA,SAASC,MAAT,EAAiBC,WAAjB,EAA8BC,OAA9B,EAAuCC,UAAvC,QAAyD,oBAAzD;AACA,OAAOC,cAAP,MAA2B,6BAA3B;AACA,SAASC,yBAAT,QAA0C,oBAA1C;AAEA;AACA;AACA;;AACA,OAAOC,WAAP,MAAwB,mCAAxB;AACA,OAAOC,YAAP,MAAyB,uCAAzB;;AAEA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;;AACA,MAAMC,WAAW,GAAGV,WAAW,EAA/B;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,OAA7B,GAAuC,KAAvC,CADY,CAEZ;;AACAe,MAAAA,aAAa,CAACI,OAAd,CAAyBC,WAAF,IAAmBA,WAAnB,aAAmBA,WAAnB,uBAAmBA,WAAW,EAArD;AACA5C,MAAAA,WAAW,CAACkC,KAAZ,CAAmBzB,YAAnB;AACA,KALD,CA7CgC,CAmDhC;AACA;AACA;AACA,GAtDwB,EAsDtB,CAAEF,QAAF,EAAYY,UAAZ,EAAwBf,kBAAxB,EAA4CkB,eAA5C,CAtDsB,CAAzB;AAwDA,SAAOlB,kBAAkB,GAAGmB,SAAH,GAAehB,QAAQ,CAACoB,MAAT,CAAiBzB,SAAjB,CAAxC;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport { useRef, useCallback, useMemo, useReducer } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst noop = () => {};\nconst renderQueue = createQueue();\n\n/** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://reactjs.org/docs/hooks-rules.html).\n *\n * @param {Function|StoreDescriptor|string} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * implementing this hook. The function receives\n * the `registry.select` method on the first\n * argument and the `registry` on the second\n * argument.\n * When a store key is passed, all selectors for\n * the store will be returned. This is only meant\n * for usage of these selectors in event\n * callbacks, not for data needed to create the\n * element tree.\n * @param {Array} deps If provided, this memoizes the mapSelect so the\n * same `mapSelect` is invoked on every state\n * change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( 'my-shop' ).getPrice( 'hammer', currency )\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( 'my-shop' );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n *\n * @return {Function} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\tconst hasMappingFunction = 'function' === typeof mapSelect;\n\n\t// If we're recalling a store by its name or by\n\t// its descriptor then we won't be caching the\n\t// calls to `mapSelect` because we won't be calling it.\n\tif ( ! hasMappingFunction ) {\n\t\tdeps = [];\n\t}\n\n\t// Because of the \"rule of hooks\" we have to call `useCallback`\n\t// on every invocation whether or not we have a real function\n\t// for `mapSelect`. we'll create this intermediate variable to\n\t// fulfill that need and then reference it with our \"real\"\n\t// `_mapSelect` if we can.\n\tconst callbackMapper = useCallback(\n\t\thasMappingFunction ? mapSelect : noop,\n\t\tdeps\n\t);\n\tconst _mapSelect = hasMappingFunction ? callbackMapper : null;\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\t// React can sometimes clear the `useMemo` cache.\n\t// We use the cache-stable `useMemoOne` to avoid\n\t// losing queues.\n\tconst queueContext = useMemoOne( () => ( { queue: true } ), [ registry ] );\n\tconst [ , forceRender ] = useReducer( ( s ) => s + 1, 0 );\n\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\tconst isMountedAndNotUnsubscribing = useRef();\n\n\t// Keep track of the stores being selected in the _mapSelect function,\n\t// and only subscribe to those stores later.\n\tconst listeningStores = useRef( [] );\n\tconst trapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__experimentalMarkListeningStores(\n\t\t\t\tcallback,\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput;\n\n\tif ( _mapSelect ) {\n\t\tmapOutput = latestMapOutput.current;\n\t\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\t\tconst lastMapSelectFailed = !! latestMapOutputError.current;\n\n\t\tif ( hasReplacedMapSelect || lastMapSelectFailed ) {\n\t\t\ttry {\n\t\t\t\tmapOutput = trapSelect( () =>\n\t\t\t\t\t_mapSelect( registry.select, registry )\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tlet errorMessage = `An error occurred while running 'mapSelect': ${ error.message }`;\n\n\t\t\t\tif ( latestMapOutputError.current ) {\n\t\t\t\t\terrorMessage += `\\nThe error may be correlated with this previous error:\\n`;\n\t\t\t\t\terrorMessage += `${ latestMapOutputError.current.stack }\\n\\n`;\n\t\t\t\t\terrorMessage += 'Original stack trace:';\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.error( errorMessage );\n\t\t\t}\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlatestMapSelect.current = _mapSelect;\n\t\tlatestMapOutput.current = mapOutput;\n\t\tlatestMapOutputError.current = undefined;\n\t\tisMountedAndNotUnsubscribing.current = true;\n\n\t\t// This has to run after the other ref updates\n\t\t// to avoid using stale values in the flushed\n\t\t// callbacks or potentially overwriting a\n\t\t// changed `latestMapOutput.current`.\n\t\tif ( latestIsAsync.current !== isAsync ) {\n\t\t\tlatestIsAsync.current = isAsync;\n\t\t\trenderQueue.flush( queueContext );\n\t\t}\n\t} );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst onStoreChange = () => {\n\t\t\tif ( isMountedAndNotUnsubscribing.current ) {\n\t\t\t\ttry {\n\t\t\t\t\tconst newMapOutput = trapSelect( () =>\n\t\t\t\t\t\tlatestMapSelect.current( registry.select, registry )\n\t\t\t\t\t);\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tisShallowEqual( latestMapOutput.current, newMapOutput )\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t\t}\n\t\t\t\tforceRender();\n\t\t\t}\n\t\t};\n\n\t\t// Catch any possible state changes during mount before the subscription\n\t\t// could be set.\n\t\tif ( latestIsAsync.current ) {\n\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t} else {\n\t\t\tonStoreChange();\n\t\t}\n\n\t\tconst onChange = () => {\n\t\t\tif ( latestIsAsync.current ) {\n\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t} else {\n\t\t\t\tonStoreChange();\n\t\t\t}\n\t\t};\n\n\t\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__experimentalSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\treturn () => {\n\t\t\tisMountedAndNotUnsubscribing.current = false;\n\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe?.() );\n\t\t\trenderQueue.flush( queueContext );\n\t\t};\n\t\t// If you're tempted to eliminate the spread dependencies below don't do it!\n\t\t// We're passing these in from the calling function and want to make sure we're\n\t\t// examining every individual value inside the `deps` array.\n\t}, [ registry, trapSelect, hasMappingFunction, depsChangedFlag ] );\n\n\treturn hasMappingFunction ? mapOutput : registry.select( mapSelect );\n}\n"]}