@wordpress/notices 5.44.0 → 5.44.1-next.v.202604201441.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.
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // packages/notices/src/store/reducer.ts
@@ -33,8 +23,8 @@ __export(reducer_exports, {
33
23
  default: () => reducer_default
34
24
  });
35
25
  module.exports = __toCommonJS(reducer_exports);
36
- var import_on_sub_key = __toESM(require("./utils/on-sub-key.cjs"));
37
- var notices = (0, import_on_sub_key.default)("context")((state = [], action) => {
26
+ var import_data = require("@wordpress/data");
27
+ var notices = (0, import_data.keyedReducer)("context")((state = [], action) => {
38
28
  switch (action.type) {
39
29
  case "CREATE_NOTICE":
40
30
  return [
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/store/reducer.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { Notice, ReducerAction } from './types';\nimport onSubKey from './utils/on-sub-key';\n\n/**\n * Reducer returning the next notices state. The notices state is an object\n * where each key is a context, its value an array of notice objects.\n *\n * @param state Current state.\n * @param action Dispatched action.\n *\n * @return Updated state.\n */\nconst notices = onSubKey( 'context' )< Array< Notice >, ReducerAction >( (\n\tstate = [],\n\taction\n) => {\n\tswitch ( action.type ) {\n\t\tcase 'CREATE_NOTICE':\n\t\t\t// Avoid duplicates on ID.\n\t\t\treturn [\n\t\t\t\t...state.filter( ( { id } ) => id !== action.notice.id ),\n\t\t\t\taction.notice,\n\t\t\t];\n\n\t\tcase 'REMOVE_NOTICE':\n\t\t\treturn state.filter( ( { id } ) => id !== action.id );\n\n\t\tcase 'REMOVE_NOTICES':\n\t\t\treturn state.filter( ( { id } ) => ! action.ids.includes( id ) );\n\n\t\tcase 'REMOVE_ALL_NOTICES':\n\t\t\treturn state.filter( ( { type } ) => type !== action.noticeType );\n\n\t\tdefault:\n\t\t\treturn state;\n\t}\n} );\n\nexport default notices;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,wBAAqB;AAWrB,IAAM,cAAU,kBAAAA,SAAU,SAAU,EAAqC,CACxE,QAAQ,CAAC,GACT,WACI;AACJ,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK;AAEJ,aAAO;AAAA,QACN,GAAG,MAAM,OAAQ,CAAE,EAAE,GAAG,MAAO,OAAO,OAAO,OAAO,EAAG;AAAA,QACvD,OAAO;AAAA,MACR;AAAA,IAED,KAAK;AACJ,aAAO,MAAM,OAAQ,CAAE,EAAE,GAAG,MAAO,OAAO,OAAO,EAAG;AAAA,IAErD,KAAK;AACJ,aAAO,MAAM,OAAQ,CAAE,EAAE,GAAG,MAAO,CAAE,OAAO,IAAI,SAAU,EAAG,CAAE;AAAA,IAEhE,KAAK;AACJ,aAAO,MAAM,OAAQ,CAAE,EAAE,KAAK,MAAO,SAAS,OAAO,UAAW;AAAA,IAEjE;AACC,aAAO;AAAA,EACT;AACD,CAAE;AAEF,IAAO,kBAAQ;",
6
- "names": ["onSubKey"]
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { keyedReducer } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport type { Notice, ReducerAction } from './types';\n\n/**\n * Reducer returning the next notices state. The notices state is an object\n * where each key is a context, its value an array of notice objects.\n *\n * @param state Current state.\n * @param action Dispatched action.\n *\n * @return Updated state.\n */\nconst notices = keyedReducer< Array< Notice >, ReducerAction >( 'context' )( (\n\tstate = [],\n\taction\n) => {\n\tswitch ( action.type ) {\n\t\tcase 'CREATE_NOTICE':\n\t\t\t// Avoid duplicates on ID.\n\t\t\treturn [\n\t\t\t\t...state.filter( ( { id } ) => id !== action.notice.id ),\n\t\t\t\taction.notice,\n\t\t\t];\n\n\t\tcase 'REMOVE_NOTICE':\n\t\t\treturn state.filter( ( { id } ) => id !== action.id );\n\n\t\tcase 'REMOVE_NOTICES':\n\t\t\treturn state.filter( ( { id } ) => ! action.ids.includes( id ) );\n\n\t\tcase 'REMOVE_ALL_NOTICES':\n\t\t\treturn state.filter( ( { type } ) => type !== action.noticeType );\n\n\t\tdefault:\n\t\t\treturn state;\n\t}\n} );\n\nexport default notices;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAA6B;AAgB7B,IAAM,cAAU,0BAAgD,SAAU,EAAG,CAC5E,QAAQ,CAAC,GACT,WACI;AACJ,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK;AAEJ,aAAO;AAAA,QACN,GAAG,MAAM,OAAQ,CAAE,EAAE,GAAG,MAAO,OAAO,OAAO,OAAO,EAAG;AAAA,QACvD,OAAO;AAAA,MACR;AAAA,IAED,KAAK;AACJ,aAAO,MAAM,OAAQ,CAAE,EAAE,GAAG,MAAO,OAAO,OAAO,EAAG;AAAA,IAErD,KAAK;AACJ,aAAO,MAAM,OAAQ,CAAE,EAAE,GAAG,MAAO,CAAE,OAAO,IAAI,SAAU,EAAG,CAAE;AAAA,IAEhE,KAAK;AACJ,aAAO,MAAM,OAAQ,CAAE,EAAE,KAAK,MAAO,SAAS,OAAO,UAAW;AAAA,IAEjE;AACC,aAAO;AAAA,EACT;AACD,CAAE;AAEF,IAAO,kBAAQ;",
6
+ "names": []
7
7
  }
@@ -1,6 +1,6 @@
1
1
  // packages/notices/src/store/reducer.ts
2
- import onSubKey from "./utils/on-sub-key.mjs";
3
- var notices = onSubKey("context")((state = [], action) => {
2
+ import { keyedReducer } from "@wordpress/data";
3
+ var notices = keyedReducer("context")((state = [], action) => {
4
4
  switch (action.type) {
5
5
  case "CREATE_NOTICE":
6
6
  return [
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/store/reducer.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { Notice, ReducerAction } from './types';\nimport onSubKey from './utils/on-sub-key';\n\n/**\n * Reducer returning the next notices state. The notices state is an object\n * where each key is a context, its value an array of notice objects.\n *\n * @param state Current state.\n * @param action Dispatched action.\n *\n * @return Updated state.\n */\nconst notices = onSubKey( 'context' )< Array< Notice >, ReducerAction >( (\n\tstate = [],\n\taction\n) => {\n\tswitch ( action.type ) {\n\t\tcase 'CREATE_NOTICE':\n\t\t\t// Avoid duplicates on ID.\n\t\t\treturn [\n\t\t\t\t...state.filter( ( { id } ) => id !== action.notice.id ),\n\t\t\t\taction.notice,\n\t\t\t];\n\n\t\tcase 'REMOVE_NOTICE':\n\t\t\treturn state.filter( ( { id } ) => id !== action.id );\n\n\t\tcase 'REMOVE_NOTICES':\n\t\t\treturn state.filter( ( { id } ) => ! action.ids.includes( id ) );\n\n\t\tcase 'REMOVE_ALL_NOTICES':\n\t\t\treturn state.filter( ( { type } ) => type !== action.noticeType );\n\n\t\tdefault:\n\t\t\treturn state;\n\t}\n} );\n\nexport default notices;\n"],
5
- "mappings": ";AAIA,OAAO,cAAc;AAWrB,IAAM,UAAU,SAAU,SAAU,EAAqC,CACxE,QAAQ,CAAC,GACT,WACI;AACJ,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK;AAEJ,aAAO;AAAA,QACN,GAAG,MAAM,OAAQ,CAAE,EAAE,GAAG,MAAO,OAAO,OAAO,OAAO,EAAG;AAAA,QACvD,OAAO;AAAA,MACR;AAAA,IAED,KAAK;AACJ,aAAO,MAAM,OAAQ,CAAE,EAAE,GAAG,MAAO,OAAO,OAAO,EAAG;AAAA,IAErD,KAAK;AACJ,aAAO,MAAM,OAAQ,CAAE,EAAE,GAAG,MAAO,CAAE,OAAO,IAAI,SAAU,EAAG,CAAE;AAAA,IAEhE,KAAK;AACJ,aAAO,MAAM,OAAQ,CAAE,EAAE,KAAK,MAAO,SAAS,OAAO,UAAW;AAAA,IAEjE;AACC,aAAO;AAAA,EACT;AACD,CAAE;AAEF,IAAO,kBAAQ;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { keyedReducer } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport type { Notice, ReducerAction } from './types';\n\n/**\n * Reducer returning the next notices state. The notices state is an object\n * where each key is a context, its value an array of notice objects.\n *\n * @param state Current state.\n * @param action Dispatched action.\n *\n * @return Updated state.\n */\nconst notices = keyedReducer< Array< Notice >, ReducerAction >( 'context' )( (\n\tstate = [],\n\taction\n) => {\n\tswitch ( action.type ) {\n\t\tcase 'CREATE_NOTICE':\n\t\t\t// Avoid duplicates on ID.\n\t\t\treturn [\n\t\t\t\t...state.filter( ( { id } ) => id !== action.notice.id ),\n\t\t\t\taction.notice,\n\t\t\t];\n\n\t\tcase 'REMOVE_NOTICE':\n\t\t\treturn state.filter( ( { id } ) => id !== action.id );\n\n\t\tcase 'REMOVE_NOTICES':\n\t\t\treturn state.filter( ( { id } ) => ! action.ids.includes( id ) );\n\n\t\tcase 'REMOVE_ALL_NOTICES':\n\t\t\treturn state.filter( ( { type } ) => type !== action.noticeType );\n\n\t\tdefault:\n\t\t\treturn state;\n\t}\n} );\n\nexport default notices;\n"],
5
+ "mappings": ";AAGA,SAAS,oBAAoB;AAgB7B,IAAM,UAAU,aAAgD,SAAU,EAAG,CAC5E,QAAQ,CAAC,GACT,WACI;AACJ,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK;AAEJ,aAAO;AAAA,QACN,GAAG,MAAM,OAAQ,CAAE,EAAE,GAAG,MAAO,OAAO,OAAO,OAAO,EAAG;AAAA,QACvD,OAAO;AAAA,MACR;AAAA,IAED,KAAK;AACJ,aAAO,MAAM,OAAQ,CAAE,EAAE,GAAG,MAAO,OAAO,OAAO,EAAG;AAAA,IAErD,KAAK;AACJ,aAAO,MAAM,OAAQ,CAAE,EAAE,GAAG,MAAO,CAAE,OAAO,IAAI,SAAU,EAAG,CAAE;AAAA,IAEhE,KAAK;AACJ,aAAO,MAAM,OAAQ,CAAE,EAAE,KAAK,MAAO,SAAS,OAAO,UAAW;AAAA,IAEjE;AACC,aAAO;AAAA,EACT;AACD,CAAE;AAEF,IAAO,kBAAQ;",
6
6
  "names": []
7
7
  }
@@ -11,6 +11,6 @@ import type { Notice, ReducerAction } from './types';
11
11
  *
12
12
  * @return Updated state.
13
13
  */
14
- declare const notices: (state: Record<string, Notice[]> | undefined, action: ReducerAction) => Record<string, Notice[]>;
14
+ declare const notices: import("redux").Reducer<Record<string, Notice[]>, ReducerAction>;
15
15
  export default notices;
16
16
  //# sourceMappingURL=reducer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/store/reducer.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAGrD;;;;;;;;GAQG;AACH,QAAA,MAAM,OAAO,kGAwBV,CAAC;AAEJ,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../../src/store/reducer.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAErD;;;;;;;;GAQG;AACH,QAAA,MAAM,OAAO,kEAwBV,CAAC;AAEJ,eAAe,OAAO,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/notices",
3
- "version": "5.44.0",
3
+ "version": "5.44.1-next.v.202604201441.0+dab6d8c07",
4
4
  "description": "State management for notices.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -43,9 +43,9 @@
43
43
  "wpScript": true,
44
44
  "types": "build-types",
45
45
  "dependencies": {
46
- "@wordpress/a11y": "^4.44.0",
47
- "@wordpress/components": "^32.6.0",
48
- "@wordpress/data": "^10.44.0",
46
+ "@wordpress/a11y": "^4.44.1-next.v.202604201441.0+dab6d8c07",
47
+ "@wordpress/components": "^33.0.1-next.v.202604201441.0+dab6d8c07",
48
+ "@wordpress/data": "^10.45.1-next.v.202604201441.0+dab6d8c07",
49
49
  "clsx": "^2.1.1"
50
50
  },
51
51
  "devDependencies": {
@@ -57,5 +57,5 @@
57
57
  "publishConfig": {
58
58
  "access": "public"
59
59
  },
60
- "gitHead": "b862d8c84121a47bbeff882f6c87e61681ce2e0d"
60
+ "gitHead": "c788005ba4ee2a34851c1217c51602656aa7c3a6"
61
61
  }
@@ -1,8 +1,12 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { keyedReducer } from '@wordpress/data';
5
+
1
6
  /**
2
7
  * Internal dependencies
3
8
  */
4
9
  import type { Notice, ReducerAction } from './types';
5
- import onSubKey from './utils/on-sub-key';
6
10
 
7
11
  /**
8
12
  * Reducer returning the next notices state. The notices state is an object
@@ -13,7 +17,7 @@ import onSubKey from './utils/on-sub-key';
13
17
  *
14
18
  * @return Updated state.
15
19
  */
16
- const notices = onSubKey( 'context' )< Array< Notice >, ReducerAction >( (
20
+ const notices = keyedReducer< Array< Notice >, ReducerAction >( 'context' )( (
17
21
  state = [],
18
22
  action
19
23
  ) => {
@@ -1,46 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // packages/notices/src/store/utils/on-sub-key.ts
21
- var on_sub_key_exports = {};
22
- __export(on_sub_key_exports, {
23
- default: () => on_sub_key_default,
24
- onSubKey: () => onSubKey
25
- });
26
- module.exports = __toCommonJS(on_sub_key_exports);
27
- var onSubKey = (actionProperty) => (reducer) => (state = {}, action) => {
28
- const key = action[actionProperty];
29
- if (key === void 0) {
30
- return state;
31
- }
32
- const nextKeyState = reducer(state[key], action);
33
- if (nextKeyState === state[key]) {
34
- return state;
35
- }
36
- return {
37
- ...state,
38
- [key]: nextKeyState
39
- };
40
- };
41
- var on_sub_key_default = onSubKey;
42
- // Annotate the CommonJS export names for ESM import in node:
43
- 0 && (module.exports = {
44
- onSubKey
45
- });
46
- //# sourceMappingURL=on-sub-key.cjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/store/utils/on-sub-key.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport type { Reducer, Action } from 'redux';\n\n/**\n * Higher-order reducer creator which creates a combined reducer object, keyed\n * by a property on the action object.\n *\n * @param actionProperty Action property by which to key object.\n *\n * @return Higher-order reducer.\n */\nexport const onSubKey =\n\t( actionProperty: string ) =>\n\t< S, A extends Action & Record< string, any > >(\n\t\treducer: Reducer< S, A >\n\t) =>\n\t( state: Record< string, S > = {}, action: A ) => {\n\t\t// Retrieve subkey from action. Do not track if undefined; useful for cases\n\t\t// where reducer is scoped by action shape.\n\t\tconst key = action[ actionProperty ];\n\t\tif ( key === undefined ) {\n\t\t\treturn state;\n\t\t}\n\n\t\t// Avoid updating state if unchanged. Note that this also accounts for a\n\t\t// reducer which returns undefined on a key which is not yet tracked.\n\t\tconst nextKeyState = reducer( state[ key ], action );\n\t\tif ( nextKeyState === state[ key ] ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ key ]: nextKeyState,\n\t\t};\n\t};\n\nexport default onSubKey;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaO,IAAM,WACZ,CAAE,mBACF,CACC,YAED,CAAE,QAA6B,CAAC,GAAG,WAAe;AAGjD,QAAM,MAAM,OAAQ,cAAe;AACnC,MAAK,QAAQ,QAAY;AACxB,WAAO;AAAA,EACR;AAIA,QAAM,eAAe,QAAS,MAAO,GAAI,GAAG,MAAO;AACnD,MAAK,iBAAiB,MAAO,GAAI,GAAI;AACpC,WAAO;AAAA,EACR;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,GAAI,GAAG;AAAA,EACV;AACD;AAED,IAAO,qBAAQ;",
6
- "names": []
7
- }
@@ -1,21 +0,0 @@
1
- // packages/notices/src/store/utils/on-sub-key.ts
2
- var onSubKey = (actionProperty) => (reducer) => (state = {}, action) => {
3
- const key = action[actionProperty];
4
- if (key === void 0) {
5
- return state;
6
- }
7
- const nextKeyState = reducer(state[key], action);
8
- if (nextKeyState === state[key]) {
9
- return state;
10
- }
11
- return {
12
- ...state,
13
- [key]: nextKeyState
14
- };
15
- };
16
- var on_sub_key_default = onSubKey;
17
- export {
18
- on_sub_key_default as default,
19
- onSubKey
20
- };
21
- //# sourceMappingURL=on-sub-key.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/store/utils/on-sub-key.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport type { Reducer, Action } from 'redux';\n\n/**\n * Higher-order reducer creator which creates a combined reducer object, keyed\n * by a property on the action object.\n *\n * @param actionProperty Action property by which to key object.\n *\n * @return Higher-order reducer.\n */\nexport const onSubKey =\n\t( actionProperty: string ) =>\n\t< S, A extends Action & Record< string, any > >(\n\t\treducer: Reducer< S, A >\n\t) =>\n\t( state: Record< string, S > = {}, action: A ) => {\n\t\t// Retrieve subkey from action. Do not track if undefined; useful for cases\n\t\t// where reducer is scoped by action shape.\n\t\tconst key = action[ actionProperty ];\n\t\tif ( key === undefined ) {\n\t\t\treturn state;\n\t\t}\n\n\t\t// Avoid updating state if unchanged. Note that this also accounts for a\n\t\t// reducer which returns undefined on a key which is not yet tracked.\n\t\tconst nextKeyState = reducer( state[ key ], action );\n\t\tif ( nextKeyState === state[ key ] ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ key ]: nextKeyState,\n\t\t};\n\t};\n\nexport default onSubKey;\n"],
5
- "mappings": ";AAaO,IAAM,WACZ,CAAE,mBACF,CACC,YAED,CAAE,QAA6B,CAAC,GAAG,WAAe;AAGjD,QAAM,MAAM,OAAQ,cAAe;AACnC,MAAK,QAAQ,QAAY;AACxB,WAAO;AAAA,EACR;AAIA,QAAM,eAAe,QAAS,MAAO,GAAI,GAAG,MAAO;AACnD,MAAK,iBAAiB,MAAO,GAAI,GAAI;AACpC,WAAO;AAAA,EACR;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,GAAI,GAAG;AAAA,EACV;AACD;AAED,IAAO,qBAAQ;",
6
- "names": []
7
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import type { Reducer, Action } from 'redux';
5
- /**
6
- * Higher-order reducer creator which creates a combined reducer object, keyed
7
- * by a property on the action object.
8
- *
9
- * @param actionProperty Action property by which to key object.
10
- *
11
- * @return Higher-order reducer.
12
- */
13
- export declare const onSubKey: (actionProperty: string) => <S, A extends Action & Record<string, any>>(reducer: Reducer<S, A>) => (state: Record<string, S> | undefined, action: A) => Record<string, S>;
14
- export default onSubKey;
15
- //# sourceMappingURL=on-sub-key.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"on-sub-key.d.ts","sourceRoot":"","sources":["../../../src/store/utils/on-sub-key.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE7C;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GAClB,gBAAgB,MAAM,MACtB,CAAC,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,CAAE,MAAM,EAAE,GAAG,CAAE,EAC5C,SAAS,OAAO,CAAE,CAAC,EAAE,CAAC,CAAE,MAEvB,OAAO,MAAM,CAAE,MAAM,EAAE,CAAC,CAAE,YAAK,EAAE,QAAQ,CAAC,sBAmB3C,CAAC;AAEH,eAAe,QAAQ,CAAC"}
@@ -1,40 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import type { Reducer, Action } from 'redux';
5
-
6
- /**
7
- * Higher-order reducer creator which creates a combined reducer object, keyed
8
- * by a property on the action object.
9
- *
10
- * @param actionProperty Action property by which to key object.
11
- *
12
- * @return Higher-order reducer.
13
- */
14
- export const onSubKey =
15
- ( actionProperty: string ) =>
16
- < S, A extends Action & Record< string, any > >(
17
- reducer: Reducer< S, A >
18
- ) =>
19
- ( state: Record< string, S > = {}, action: A ) => {
20
- // Retrieve subkey from action. Do not track if undefined; useful for cases
21
- // where reducer is scoped by action shape.
22
- const key = action[ actionProperty ];
23
- if ( key === undefined ) {
24
- return state;
25
- }
26
-
27
- // Avoid updating state if unchanged. Note that this also accounts for a
28
- // reducer which returns undefined on a key which is not yet tracked.
29
- const nextKeyState = reducer( state[ key ], action );
30
- if ( nextKeyState === state[ key ] ) {
31
- return state;
32
- }
33
-
34
- return {
35
- ...state,
36
- [ key ]: nextKeyState,
37
- };
38
- };
39
-
40
- export default onSubKey;