@wordpress/interface 4.3.0 → 4.5.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,172 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.multipleEnableItems = multipleEnableItems;
8
- exports.preferences = exports.preferenceDefaults = void 0;
9
- exports.singleEnableItems = singleEnableItems;
10
-
11
- var _lodash = require("lodash");
12
-
13
- var _data = require("@wordpress/data");
14
-
15
- /**
16
- * External dependencies
17
- */
18
-
19
- /**
20
- * WordPress dependencies
21
- */
22
-
23
- /**
24
- * Reducer to keep tract of the active area per scope.
25
- *
26
- * @param {boolean} state Previous state.
27
- * @param {Object} action Action object.
28
- * @param {string} action.type Action type.
29
- * @param {string} action.itemType Type of item.
30
- * @param {string} action.scope Item scope.
31
- * @param {string} action.item Item name.
32
- *
33
- * @return {Object} Updated state.
34
- */
35
- function singleEnableItems() {
36
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
37
- let {
38
- type,
39
- itemType,
40
- scope,
41
- item
42
- } = arguments.length > 1 ? arguments[1] : undefined;
43
-
44
- if (type !== 'SET_SINGLE_ENABLE_ITEM' || !itemType || !scope) {
45
- return state;
46
- }
47
-
48
- return { ...state,
49
- [itemType]: { ...state[itemType],
50
- [scope]: item || null
51
- }
52
- };
53
- }
54
- /**
55
- * Reducer keeping track of the "pinned" items per scope.
56
- *
57
- * @param {boolean} state Previous state.
58
- * @param {Object} action Action object.
59
- * @param {string} action.type Action type.
60
- * @param {string} action.itemType Type of item.
61
- * @param {string} action.scope Item scope.
62
- * @param {string} action.item Item name.
63
- * @param {boolean} action.isEnable Whether the item is pinned.
64
- *
65
- * @return {Object} Updated state.
66
- */
67
-
68
-
69
- function multipleEnableItems() {
70
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
71
- let {
72
- type,
73
- itemType,
74
- scope,
75
- item,
76
- isEnable
77
- } = arguments.length > 1 ? arguments[1] : undefined;
78
-
79
- if (type !== 'SET_MULTIPLE_ENABLE_ITEM' || !itemType || !scope || !item || (0, _lodash.get)(state, [itemType, scope, item]) === isEnable) {
80
- return state;
81
- }
82
-
83
- const currentTypeState = state[itemType] || {};
84
- const currentScopeState = currentTypeState[scope] || {};
85
- return { ...state,
86
- [itemType]: { ...currentTypeState,
87
- [scope]: { ...currentScopeState,
88
- [item]: isEnable || false
89
- }
90
- }
91
- };
92
- }
93
- /**
94
- * Reducer returning the defaults for user preferences.
95
- *
96
- * This is kept intentionally separate from the preferences
97
- * themselves so that defaults are not persisted.
98
- *
99
- * @param {Object} state Current state.
100
- * @param {Object} action Dispatched action.
101
- *
102
- * @return {Object} Updated state.
103
- */
104
-
105
-
106
- const preferenceDefaults = (0, _data.combineReducers)({
107
- features() {
108
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
109
- let action = arguments.length > 1 ? arguments[1] : undefined;
110
-
111
- if (action.type === 'SET_FEATURE_DEFAULTS') {
112
- const {
113
- scope,
114
- defaults
115
- } = action;
116
- return { ...state,
117
- [scope]: { ...state[scope],
118
- ...defaults
119
- }
120
- };
121
- }
122
-
123
- return state;
124
- }
125
-
126
- });
127
- /**
128
- * Reducer returning the user preferences.
129
- *
130
- * @param {Object} state Current state.
131
- * @param {Object} action Dispatched action.
132
- *
133
- * @return {Object} Updated state.
134
- */
135
-
136
- exports.preferenceDefaults = preferenceDefaults;
137
- const preferences = (0, _data.combineReducers)({
138
- features() {
139
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
140
- let action = arguments.length > 1 ? arguments[1] : undefined;
141
-
142
- if (action.type === 'SET_FEATURE_VALUE') {
143
- const {
144
- scope,
145
- featureName,
146
- value
147
- } = action;
148
- return { ...state,
149
- [scope]: { ...state[scope],
150
- [featureName]: value
151
- }
152
- };
153
- }
154
-
155
- return state;
156
- }
157
-
158
- });
159
- exports.preferences = preferences;
160
- const enableItems = (0, _data.combineReducers)({
161
- singleEnableItems,
162
- multipleEnableItems
163
- });
164
-
165
- var _default = (0, _data.combineReducers)({
166
- enableItems,
167
- preferenceDefaults,
168
- preferences
169
- });
170
-
171
- exports.default = _default;
172
- //# sourceMappingURL=reducer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/interface/src/store/reducer.js"],"names":["singleEnableItems","state","type","itemType","scope","item","multipleEnableItems","isEnable","currentTypeState","currentScopeState","preferenceDefaults","features","action","defaults","preferences","featureName","value","enableItems"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,iBAAT,GAGL;AAAA,MAFDC,KAEC,uEAFO,EAEP;AAAA,MADD;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,QAAR;AAAkBC,IAAAA,KAAlB;AAAyBC,IAAAA;AAAzB,GACC;;AACD,MAAKH,IAAI,KAAK,wBAAT,IAAqC,CAAEC,QAAvC,IAAmD,CAAEC,KAA1D,EAAkE;AACjE,WAAOH,KAAP;AACA;;AAED,SAAO,EACN,GAAGA,KADG;AAEN,KAAEE,QAAF,GAAc,EACb,GAAGF,KAAK,CAAEE,QAAF,CADK;AAEb,OAAEC,KAAF,GAAWC,IAAI,IAAI;AAFN;AAFR,GAAP;AAOA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,mBAAT,GAGL;AAAA,MAFDL,KAEC,uEAFO,EAEP;AAAA,MADD;AAAEC,IAAAA,IAAF;AAAQC,IAAAA,QAAR;AAAkBC,IAAAA,KAAlB;AAAyBC,IAAAA,IAAzB;AAA+BE,IAAAA;AAA/B,GACC;;AACD,MACCL,IAAI,KAAK,0BAAT,IACA,CAAEC,QADF,IAEA,CAAEC,KAFF,IAGA,CAAEC,IAHF,IAIA,iBAA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AGX,KADG;AAEN,SAAEG,KAAF,GAAW,EACV,GAAGH,KAAK,CAAEG,KAAF,CADE;AAEV,WAAEW,WAAF,GAAiBC;AAFP;AAFL,OAAP;AAOA;;AAED,WAAOf,KAAP;AACA;;AAd0C,CAAjB,CAApB;;AAiBP,MAAMgB,WAAW,GAAG,2BAAiB;AACpCjB,EAAAA,iBADoC;AAEpCM,EAAAA;AAFoC,CAAjB,CAApB;;eAKe,2BAAiB;AAC/BW,EAAAA,WAD+B;AAE/BP,EAAAA,kBAF+B;AAG/BI,EAAAA;AAH+B,CAAjB,C","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Reducer to keep tract of the active area per scope.\n *\n * @param {boolean} state Previous state.\n * @param {Object} action Action object.\n * @param {string} action.type Action type.\n * @param {string} action.itemType Type of item.\n * @param {string} action.scope Item scope.\n * @param {string} action.item Item name.\n *\n * @return {Object} Updated state.\n */\nexport function singleEnableItems(\n\tstate = {},\n\t{ type, itemType, scope, item }\n) {\n\tif ( type !== 'SET_SINGLE_ENABLE_ITEM' || ! itemType || ! scope ) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\t...state,\n\t\t[ itemType ]: {\n\t\t\t...state[ itemType ],\n\t\t\t[ scope ]: item || null,\n\t\t},\n\t};\n}\n\n/**\n * Reducer keeping track of the \"pinned\" items per scope.\n *\n * @param {boolean} state Previous state.\n * @param {Object} action Action object.\n * @param {string} action.type Action type.\n * @param {string} action.itemType Type of item.\n * @param {string} action.scope Item scope.\n * @param {string} action.item Item name.\n * @param {boolean} action.isEnable Whether the item is pinned.\n *\n * @return {Object} Updated state.\n */\nexport function multipleEnableItems(\n\tstate = {},\n\t{ type, itemType, scope, item, isEnable }\n) {\n\tif (\n\t\ttype !== 'SET_MULTIPLE_ENABLE_ITEM' ||\n\t\t! itemType ||\n\t\t! scope ||\n\t\t! item ||\n\t\tget( state, [ itemType, scope, item ] ) === isEnable\n\t) {\n\t\treturn state;\n\t}\n\tconst currentTypeState = state[ itemType ] || {};\n\tconst currentScopeState = currentTypeState[ scope ] || {};\n\n\treturn {\n\t\t...state,\n\t\t[ itemType ]: {\n\t\t\t...currentTypeState,\n\t\t\t[ scope ]: {\n\t\t\t\t...currentScopeState,\n\t\t\t\t[ item ]: isEnable || false,\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Reducer returning the defaults for user preferences.\n *\n * This is kept intentionally separate from the preferences\n * themselves so that defaults are not persisted.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const preferenceDefaults = combineReducers( {\n\tfeatures( state = {}, action ) {\n\t\tif ( action.type === 'SET_FEATURE_DEFAULTS' ) {\n\t\t\tconst { scope, defaults } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ scope ]: {\n\t\t\t\t\t...state[ scope ],\n\t\t\t\t\t...defaults,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\treturn state;\n\t},\n} );\n\n/**\n * Reducer returning the user preferences.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const preferences = combineReducers( {\n\tfeatures( state = {}, action ) {\n\t\tif ( action.type === 'SET_FEATURE_VALUE' ) {\n\t\t\tconst { scope, featureName, value } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ scope ]: {\n\t\t\t\t\t...state[ scope ],\n\t\t\t\t\t[ featureName ]: value,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\treturn state;\n\t},\n} );\n\nconst enableItems = combineReducers( {\n\tsingleEnableItems,\n\tmultipleEnableItems,\n} );\n\nexport default combineReducers( {\n\tenableItems,\n\tpreferenceDefaults,\n\tpreferences,\n} );\n"]}
@@ -1,153 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { get } from 'lodash';
5
- /**
6
- * WordPress dependencies
7
- */
8
-
9
- import { combineReducers } from '@wordpress/data';
10
- /**
11
- * Reducer to keep tract of the active area per scope.
12
- *
13
- * @param {boolean} state Previous state.
14
- * @param {Object} action Action object.
15
- * @param {string} action.type Action type.
16
- * @param {string} action.itemType Type of item.
17
- * @param {string} action.scope Item scope.
18
- * @param {string} action.item Item name.
19
- *
20
- * @return {Object} Updated state.
21
- */
22
-
23
- export function singleEnableItems() {
24
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
25
- let {
26
- type,
27
- itemType,
28
- scope,
29
- item
30
- } = arguments.length > 1 ? arguments[1] : undefined;
31
-
32
- if (type !== 'SET_SINGLE_ENABLE_ITEM' || !itemType || !scope) {
33
- return state;
34
- }
35
-
36
- return { ...state,
37
- [itemType]: { ...state[itemType],
38
- [scope]: item || null
39
- }
40
- };
41
- }
42
- /**
43
- * Reducer keeping track of the "pinned" items per scope.
44
- *
45
- * @param {boolean} state Previous state.
46
- * @param {Object} action Action object.
47
- * @param {string} action.type Action type.
48
- * @param {string} action.itemType Type of item.
49
- * @param {string} action.scope Item scope.
50
- * @param {string} action.item Item name.
51
- * @param {boolean} action.isEnable Whether the item is pinned.
52
- *
53
- * @return {Object} Updated state.
54
- */
55
-
56
- export function multipleEnableItems() {
57
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
58
- let {
59
- type,
60
- itemType,
61
- scope,
62
- item,
63
- isEnable
64
- } = arguments.length > 1 ? arguments[1] : undefined;
65
-
66
- if (type !== 'SET_MULTIPLE_ENABLE_ITEM' || !itemType || !scope || !item || get(state, [itemType, scope, item]) === isEnable) {
67
- return state;
68
- }
69
-
70
- const currentTypeState = state[itemType] || {};
71
- const currentScopeState = currentTypeState[scope] || {};
72
- return { ...state,
73
- [itemType]: { ...currentTypeState,
74
- [scope]: { ...currentScopeState,
75
- [item]: isEnable || false
76
- }
77
- }
78
- };
79
- }
80
- /**
81
- * Reducer returning the defaults for user preferences.
82
- *
83
- * This is kept intentionally separate from the preferences
84
- * themselves so that defaults are not persisted.
85
- *
86
- * @param {Object} state Current state.
87
- * @param {Object} action Dispatched action.
88
- *
89
- * @return {Object} Updated state.
90
- */
91
-
92
- export const preferenceDefaults = combineReducers({
93
- features() {
94
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
95
- let action = arguments.length > 1 ? arguments[1] : undefined;
96
-
97
- if (action.type === 'SET_FEATURE_DEFAULTS') {
98
- const {
99
- scope,
100
- defaults
101
- } = action;
102
- return { ...state,
103
- [scope]: { ...state[scope],
104
- ...defaults
105
- }
106
- };
107
- }
108
-
109
- return state;
110
- }
111
-
112
- });
113
- /**
114
- * Reducer returning the user preferences.
115
- *
116
- * @param {Object} state Current state.
117
- * @param {Object} action Dispatched action.
118
- *
119
- * @return {Object} Updated state.
120
- */
121
-
122
- export const preferences = combineReducers({
123
- features() {
124
- let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
125
- let action = arguments.length > 1 ? arguments[1] : undefined;
126
-
127
- if (action.type === 'SET_FEATURE_VALUE') {
128
- const {
129
- scope,
130
- featureName,
131
- value
132
- } = action;
133
- return { ...state,
134
- [scope]: { ...state[scope],
135
- [featureName]: value
136
- }
137
- };
138
- }
139
-
140
- return state;
141
- }
142
-
143
- });
144
- const enableItems = combineReducers({
145
- singleEnableItems,
146
- multipleEnableItems
147
- });
148
- export default combineReducers({
149
- enableItems,
150
- preferenceDefaults,
151
- preferences
152
- });
153
- //# sourceMappingURL=reducer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["@wordpress/interface/src/store/reducer.js"],"names":["get","combineReducers","singleEnableItems","state","type","itemType","scope","item","multipleEnableItems","isEnable","currentTypeState","currentScopeState","preferenceDefaults","features","action","defaults","preferences","featureName","value","enableItems"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,GAAT,QAAoB,QAApB;AAEA;AACA;AACA;;AACA,SAASC,eAAT,QAAgC,iBAAhC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;A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port { get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\n\n/**\n * Reducer to keep tract of the active area per scope.\n *\n * @param {boolean} state Previous state.\n * @param {Object} action Action object.\n * @param {string} action.type Action type.\n * @param {string} action.itemType Type of item.\n * @param {string} action.scope Item scope.\n * @param {string} action.item Item name.\n *\n * @return {Object} Updated state.\n */\nexport function singleEnableItems(\n\tstate = {},\n\t{ type, itemType, scope, item }\n) {\n\tif ( type !== 'SET_SINGLE_ENABLE_ITEM' || ! itemType || ! scope ) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\t...state,\n\t\t[ itemType ]: {\n\t\t\t...state[ itemType ],\n\t\t\t[ scope ]: item || null,\n\t\t},\n\t};\n}\n\n/**\n * Reducer keeping track of the \"pinned\" items per scope.\n *\n * @param {boolean} state Previous state.\n * @param {Object} action Action object.\n * @param {string} action.type Action type.\n * @param {string} action.itemType Type of item.\n * @param {string} action.scope Item scope.\n * @param {string} action.item Item name.\n * @param {boolean} action.isEnable Whether the item is pinned.\n *\n * @return {Object} Updated state.\n */\nexport function multipleEnableItems(\n\tstate = {},\n\t{ type, itemType, scope, item, isEnable }\n) {\n\tif (\n\t\ttype !== 'SET_MULTIPLE_ENABLE_ITEM' ||\n\t\t! itemType ||\n\t\t! scope ||\n\t\t! item ||\n\t\tget( state, [ itemType, scope, item ] ) === isEnable\n\t) {\n\t\treturn state;\n\t}\n\tconst currentTypeState = state[ itemType ] || {};\n\tconst currentScopeState = currentTypeState[ scope ] || {};\n\n\treturn {\n\t\t...state,\n\t\t[ itemType ]: {\n\t\t\t...currentTypeState,\n\t\t\t[ scope ]: {\n\t\t\t\t...currentScopeState,\n\t\t\t\t[ item ]: isEnable || false,\n\t\t\t},\n\t\t},\n\t};\n}\n\n/**\n * Reducer returning the defaults for user preferences.\n *\n * This is kept intentionally separate from the preferences\n * themselves so that defaults are not persisted.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const preferenceDefaults = combineReducers( {\n\tfeatures( state = {}, action ) {\n\t\tif ( action.type === 'SET_FEATURE_DEFAULTS' ) {\n\t\t\tconst { scope, defaults } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ scope ]: {\n\t\t\t\t\t...state[ scope ],\n\t\t\t\t\t...defaults,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\treturn state;\n\t},\n} );\n\n/**\n * Reducer returning the user preferences.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Updated state.\n */\nexport const preferences = combineReducers( {\n\tfeatures( state = {}, action ) {\n\t\tif ( action.type === 'SET_FEATURE_VALUE' ) {\n\t\t\tconst { scope, featureName, value } = action;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ scope ]: {\n\t\t\t\t\t...state[ scope ],\n\t\t\t\t\t[ featureName ]: value,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\n\t\treturn state;\n\t},\n} );\n\nconst enableItems = combineReducers( {\n\tsingleEnableItems,\n\tmultipleEnableItems,\n} );\n\nexport default combineReducers( {\n\tenableItems,\n\tpreferenceDefaults,\n\tpreferences,\n} );\n"]}
@@ -1,143 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { get } from 'lodash';
5
-
6
- /**
7
- * WordPress dependencies
8
- */
9
- import { combineReducers } from '@wordpress/data';
10
-
11
- /**
12
- * Reducer to keep tract of the active area per scope.
13
- *
14
- * @param {boolean} state Previous state.
15
- * @param {Object} action Action object.
16
- * @param {string} action.type Action type.
17
- * @param {string} action.itemType Type of item.
18
- * @param {string} action.scope Item scope.
19
- * @param {string} action.item Item name.
20
- *
21
- * @return {Object} Updated state.
22
- */
23
- export function singleEnableItems(
24
- state = {},
25
- { type, itemType, scope, item }
26
- ) {
27
- if ( type !== 'SET_SINGLE_ENABLE_ITEM' || ! itemType || ! scope ) {
28
- return state;
29
- }
30
-
31
- return {
32
- ...state,
33
- [ itemType ]: {
34
- ...state[ itemType ],
35
- [ scope ]: item || null,
36
- },
37
- };
38
- }
39
-
40
- /**
41
- * Reducer keeping track of the "pinned" items per scope.
42
- *
43
- * @param {boolean} state Previous state.
44
- * @param {Object} action Action object.
45
- * @param {string} action.type Action type.
46
- * @param {string} action.itemType Type of item.
47
- * @param {string} action.scope Item scope.
48
- * @param {string} action.item Item name.
49
- * @param {boolean} action.isEnable Whether the item is pinned.
50
- *
51
- * @return {Object} Updated state.
52
- */
53
- export function multipleEnableItems(
54
- state = {},
55
- { type, itemType, scope, item, isEnable }
56
- ) {
57
- if (
58
- type !== 'SET_MULTIPLE_ENABLE_ITEM' ||
59
- ! itemType ||
60
- ! scope ||
61
- ! item ||
62
- get( state, [ itemType, scope, item ] ) === isEnable
63
- ) {
64
- return state;
65
- }
66
- const currentTypeState = state[ itemType ] || {};
67
- const currentScopeState = currentTypeState[ scope ] || {};
68
-
69
- return {
70
- ...state,
71
- [ itemType ]: {
72
- ...currentTypeState,
73
- [ scope ]: {
74
- ...currentScopeState,
75
- [ item ]: isEnable || false,
76
- },
77
- },
78
- };
79
- }
80
-
81
- /**
82
- * Reducer returning the defaults for user preferences.
83
- *
84
- * This is kept intentionally separate from the preferences
85
- * themselves so that defaults are not persisted.
86
- *
87
- * @param {Object} state Current state.
88
- * @param {Object} action Dispatched action.
89
- *
90
- * @return {Object} Updated state.
91
- */
92
- export const preferenceDefaults = combineReducers( {
93
- features( state = {}, action ) {
94
- if ( action.type === 'SET_FEATURE_DEFAULTS' ) {
95
- const { scope, defaults } = action;
96
- return {
97
- ...state,
98
- [ scope ]: {
99
- ...state[ scope ],
100
- ...defaults,
101
- },
102
- };
103
- }
104
-
105
- return state;
106
- },
107
- } );
108
-
109
- /**
110
- * Reducer returning the user preferences.
111
- *
112
- * @param {Object} state Current state.
113
- * @param {Object} action Dispatched action.
114
- *
115
- * @return {Object} Updated state.
116
- */
117
- export const preferences = combineReducers( {
118
- features( state = {}, action ) {
119
- if ( action.type === 'SET_FEATURE_VALUE' ) {
120
- const { scope, featureName, value } = action;
121
- return {
122
- ...state,
123
- [ scope ]: {
124
- ...state[ scope ],
125
- [ featureName ]: value,
126
- },
127
- };
128
- }
129
-
130
- return state;
131
- },
132
- } );
133
-
134
- const enableItems = combineReducers( {
135
- singleEnableItems,
136
- multipleEnableItems,
137
- } );
138
-
139
- export default combineReducers( {
140
- enableItems,
141
- preferenceDefaults,
142
- preferences,
143
- } );
@@ -1,107 +0,0 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import { isFeatureActive } from '../selectors';
5
-
6
- describe( 'selectors', () => {
7
- describe( 'isFeatureActive', () => {
8
- it( 'returns false if the there is no state for the feature', () => {
9
- const emptyState = {
10
- preferenceDefaults: {
11
- features: {},
12
- },
13
- preferences: {
14
- features: {},
15
- },
16
- };
17
-
18
- expect(
19
- isFeatureActive( emptyState, 'test-scope', 'testFeatureName' )
20
- ).toBe( false );
21
- } );
22
-
23
- it( 'returns false if the the default for a feature is false and there is no preference state', () => {
24
- const emptyState = {
25
- preferenceDefaults: {
26
- features: {
27
- 'test-scope': {
28
- testFeatureName: false,
29
- },
30
- },
31
- },
32
- preferences: {
33
- features: {},
34
- },
35
- };
36
-
37
- expect(
38
- isFeatureActive( emptyState, 'test-scope', 'testFeatureName' )
39
- ).toBe( false );
40
- } );
41
-
42
- it( 'returns true if the the default for a feature is true and there is no preference state', () => {
43
- const emptyState = {
44
- preferenceDefaults: {
45
- features: {
46
- 'test-scope': {
47
- testFeatureName: true,
48
- },
49
- },
50
- },
51
- preferences: {
52
- features: {},
53
- },
54
- };
55
-
56
- expect(
57
- isFeatureActive( emptyState, 'test-scope', 'testFeatureName' )
58
- ).toBe( true );
59
- } );
60
-
61
- it( 'returns true if the the default for a feature is false but the preference is true', () => {
62
- const emptyState = {
63
- preferenceDefaults: {
64
- features: {
65
- 'test-scope': {
66
- testFeatureName: false,
67
- },
68
- },
69
- },
70
- preferences: {
71
- features: {
72
- 'test-scope': {
73
- testFeatureName: true,
74
- },
75
- },
76
- },
77
- };
78
-
79
- expect(
80
- isFeatureActive( emptyState, 'test-scope', 'testFeatureName' )
81
- ).toBe( true );
82
- } );
83
-
84
- it( 'returns false if the the default for a feature is true but the preference is false', () => {
85
- const emptyState = {
86
- preferenceDefaults: {
87
- features: {
88
- 'test-scope': {
89
- testFeatureName: true,
90
- },
91
- },
92
- },
93
- preferences: {
94
- features: {
95
- 'test-scope': {
96
- testFeatureName: false,
97
- },
98
- },
99
- },
100
- };
101
-
102
- expect(
103
- isFeatureActive( emptyState, 'test-scope', 'testFeatureName' )
104
- ).toBe( false );
105
- } );
106
- } );
107
- } );