@wordpress/abilities 0.1.1-next.dc3f6d3c1.0 → 0.2.1-next.6deb34194.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 (97) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +32 -40
  3. package/build/api.js +19 -66
  4. package/build/api.js.map +3 -3
  5. package/build/index.js.map +2 -2
  6. package/build/store/actions.js +41 -31
  7. package/build/store/actions.js.map +2 -2
  8. package/build/store/constants.js +6 -15
  9. package/build/store/constants.js.map +2 -2
  10. package/build/store/index.js +1 -27
  11. package/build/store/index.js.map +3 -3
  12. package/build/store/reducer.js +2 -22
  13. package/build/store/reducer.js.map +2 -2
  14. package/build/store/selectors.js +1 -1
  15. package/build/store/selectors.js.map +2 -2
  16. package/build/store/types.js +19 -0
  17. package/build/store/types.js.map +7 -0
  18. package/build/types.js.map +1 -1
  19. package/build-module/api.js +20 -57
  20. package/build-module/api.js.map +2 -2
  21. package/build-module/index.js.map +2 -2
  22. package/build-module/store/actions.js +43 -32
  23. package/build-module/store/actions.js.map +2 -2
  24. package/build-module/store/constants.js +4 -10
  25. package/build-module/store/constants.js.map +2 -2
  26. package/build-module/store/index.js +3 -34
  27. package/build-module/store/index.js.map +2 -2
  28. package/build-module/store/reducer.js +2 -24
  29. package/build-module/store/reducer.js.map +2 -2
  30. package/build-module/store/selectors.js +1 -1
  31. package/build-module/store/selectors.js.map +2 -2
  32. package/build-module/store/types.js +1 -0
  33. package/build-module/store/types.js.map +7 -0
  34. package/build-types/api.d.ts +16 -23
  35. package/build-types/api.d.ts.map +1 -1
  36. package/build-types/index.d.ts +1 -1
  37. package/build-types/index.d.ts.map +1 -1
  38. package/build-types/store/actions.d.ts +5 -27
  39. package/build-types/store/actions.d.ts.map +1 -1
  40. package/build-types/store/constants.d.ts +2 -5
  41. package/build-types/store/constants.d.ts.map +1 -1
  42. package/build-types/store/index.d.ts +1 -1
  43. package/build-types/store/index.d.ts.map +1 -1
  44. package/build-types/store/reducer.d.ts +21 -11
  45. package/build-types/store/reducer.d.ts.map +1 -1
  46. package/build-types/store/selectors.d.ts +2 -1
  47. package/build-types/store/selectors.d.ts.map +1 -1
  48. package/build-types/store/types.d.ts +18 -0
  49. package/build-types/store/types.d.ts.map +1 -0
  50. package/build-types/types.d.ts +14 -24
  51. package/build-types/types.d.ts.map +1 -1
  52. package/package.json +15 -9
  53. package/src/api.ts +43 -123
  54. package/src/index.ts +0 -1
  55. package/src/store/actions.ts +61 -46
  56. package/src/store/constants.ts +4 -5
  57. package/src/store/index.ts +2 -34
  58. package/src/store/reducer.ts +27 -33
  59. package/src/store/selectors.ts +3 -7
  60. package/src/store/tests/actions.test.ts +100 -244
  61. package/src/store/tests/reducer.test.ts +0 -451
  62. package/src/store/tests/selectors.test.ts +1 -1
  63. package/src/store/types.ts +19 -0
  64. package/src/tests/api.test.ts +112 -158
  65. package/src/types.ts +14 -26
  66. package/build/store/resolvers.js +0 -107
  67. package/build/store/resolvers.js.map +0 -7
  68. package/build/store/tests/actions.test.js +0 -792
  69. package/build/store/tests/actions.test.js.map +0 -7
  70. package/build/store/tests/reducer.test.js +0 -743
  71. package/build/store/tests/reducer.test.js.map +0 -7
  72. package/build/store/tests/resolvers.test.js +0 -520
  73. package/build/store/tests/resolvers.test.js.map +0 -7
  74. package/build/store/tests/selectors.test.js +0 -349
  75. package/build/store/tests/selectors.test.js.map +0 -7
  76. package/build/tests/api.test.js +0 -546
  77. package/build/tests/api.test.js.map +0 -7
  78. package/build/tests/validation.test.js +0 -453
  79. package/build/tests/validation.test.js.map +0 -7
  80. package/build-module/store/resolvers.js +0 -84
  81. package/build-module/store/resolvers.js.map +0 -7
  82. package/build-module/store/tests/actions.test.js +0 -804
  83. package/build-module/store/tests/actions.test.js.map +0 -7
  84. package/build-module/store/tests/reducer.test.js +0 -726
  85. package/build-module/store/tests/reducer.test.js.map +0 -7
  86. package/build-module/store/tests/resolvers.test.js +0 -523
  87. package/build-module/store/tests/resolvers.test.js.map +0 -7
  88. package/build-module/store/tests/selectors.test.js +0 -352
  89. package/build-module/store/tests/selectors.test.js.map +0 -7
  90. package/build-module/tests/api.test.js +0 -530
  91. package/build-module/tests/api.test.js.map +0 -7
  92. package/build-module/tests/validation.test.js +0 -451
  93. package/build-module/tests/validation.test.js.map +0 -7
  94. package/build-types/store/resolvers.d.ts +0 -47
  95. package/build-types/store/resolvers.d.ts.map +0 -1
  96. package/src/store/resolvers.ts +0 -151
  97. package/src/store/tests/resolvers.test.ts +0 -642
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { createReduxStore, register, dispatch } from '@wordpress/data';
5
- import { store as coreStore } from '@wordpress/core-data';
6
- import { __ } from '@wordpress/i18n';
4
+ import { createReduxStore, register } from '@wordpress/data';
7
5
 
8
6
  /**
9
7
  * Internal dependencies
@@ -11,13 +9,7 @@ import { __ } from '@wordpress/i18n';
11
9
  import reducer from './reducer';
12
10
  import * as actions from './actions';
13
11
  import * as selectors from './selectors';
14
- import * as resolvers from './resolvers';
15
- import {
16
- STORE_NAME,
17
- ENTITY_KIND,
18
- ENTITY_NAME,
19
- ENTITY_NAME_CATEGORIES,
20
- } from './constants';
12
+ import { STORE_NAME } from './constants';
21
13
 
22
14
  /**
23
15
  * The abilities store definition.
@@ -26,30 +18,6 @@ export const store = createReduxStore( STORE_NAME, {
26
18
  reducer,
27
19
  actions,
28
20
  selectors,
29
- resolvers,
30
21
  } );
31
22
 
32
23
  register( store );
33
-
34
- dispatch( coreStore ).addEntities( [
35
- {
36
- name: ENTITY_NAME,
37
- kind: ENTITY_KIND,
38
- key: 'name',
39
- baseURL: '/wp-abilities/v1/abilities',
40
- baseURLParams: { context: 'edit' },
41
- plural: 'abilities',
42
- label: __( 'Abilities' ),
43
- supportsPagination: true,
44
- },
45
- {
46
- name: ENTITY_NAME_CATEGORIES,
47
- kind: ENTITY_KIND,
48
- key: 'slug',
49
- baseURL: '/wp-abilities/v1/categories',
50
- baseURLParams: { context: 'edit' },
51
- plural: 'ability-categories',
52
- label: __( 'Ability Categories' ),
53
- supportsPagination: true,
54
- },
55
- ] );
@@ -8,10 +8,8 @@ import { combineReducers } from '@wordpress/data';
8
8
  */
9
9
  import type { Ability, AbilityCategory } from '../types';
10
10
  import {
11
- RECEIVE_ABILITIES,
12
11
  REGISTER_ABILITY,
13
12
  UNREGISTER_ABILITY,
14
- RECEIVE_CATEGORIES,
15
13
  REGISTER_ABILITY_CATEGORY,
16
14
  UNREGISTER_ABILITY_CATEGORY,
17
15
  } from './constants';
@@ -78,16 +76,32 @@ function sanitizeCategory( category: any ): AbilityCategory {
78
76
  );
79
77
  }
80
78
 
81
- interface AbilitiesAction {
82
- type: string;
83
- abilities?: Ability[];
84
- ability?: Ability;
85
- categories?: AbilityCategory[];
86
- category?: AbilityCategory;
87
- name?: string;
88
- slug?: string;
79
+ interface RegisterAbilityAction {
80
+ type: typeof REGISTER_ABILITY;
81
+ ability: Ability;
89
82
  }
90
83
 
84
+ interface UnregisterAbilityAction {
85
+ type: typeof UNREGISTER_ABILITY;
86
+ name: string;
87
+ }
88
+
89
+ interface RegisterAbilityCategoryAction {
90
+ type: typeof REGISTER_ABILITY_CATEGORY;
91
+ category: AbilityCategory;
92
+ }
93
+
94
+ interface UnregisterAbilityCategoryAction {
95
+ type: typeof UNREGISTER_ABILITY_CATEGORY;
96
+ slug: string;
97
+ }
98
+
99
+ type AbilitiesAction = RegisterAbilityAction | UnregisterAbilityAction;
100
+
101
+ type AbilitiesCategoryAction =
102
+ | RegisterAbilityCategoryAction
103
+ | UnregisterAbilityCategoryAction;
104
+
91
105
  const DEFAULT_STATE: Record< string, Ability > = {};
92
106
 
93
107
  /**
@@ -102,16 +116,6 @@ function abilitiesByName(
102
116
  action: AbilitiesAction
103
117
  ): Record< string, Ability > {
104
118
  switch ( action.type ) {
105
- case RECEIVE_ABILITIES: {
106
- if ( ! action.abilities ) {
107
- return state;
108
- }
109
- const newState: Record< string, Ability > = {};
110
- action.abilities.forEach( ( ability ) => {
111
- newState[ ability.name ] = sanitizeAbility( ability );
112
- } );
113
- return newState;
114
- }
115
119
  case REGISTER_ABILITY: {
116
120
  if ( ! action.ability ) {
117
121
  return state;
@@ -122,7 +126,7 @@ function abilitiesByName(
122
126
  };
123
127
  }
124
128
  case UNREGISTER_ABILITY: {
125
- if ( ! action.name || ! state[ action.name ] ) {
129
+ if ( ! state[ action.name ] ) {
126
130
  return state;
127
131
  }
128
132
  const { [ action.name ]: _, ...newState } = state;
@@ -144,19 +148,9 @@ const DEFAULT_CATEGORIES_STATE: Record< string, AbilityCategory > = {};
144
148
  */
145
149
  function categoriesBySlug(
146
150
  state: Record< string, AbilityCategory > = DEFAULT_CATEGORIES_STATE,
147
- action: AbilitiesAction
151
+ action: AbilitiesCategoryAction
148
152
  ): Record< string, AbilityCategory > {
149
153
  switch ( action.type ) {
150
- case RECEIVE_CATEGORIES: {
151
- if ( ! action.categories ) {
152
- return state;
153
- }
154
- const newState: Record< string, AbilityCategory > = {};
155
- action.categories.forEach( ( category ) => {
156
- newState[ category.slug ] = sanitizeCategory( category );
157
- } );
158
- return newState;
159
- }
160
154
  case REGISTER_ABILITY_CATEGORY: {
161
155
  if ( ! action.category ) {
162
156
  return state;
@@ -167,7 +161,7 @@ function categoriesBySlug(
167
161
  };
168
162
  }
169
163
  case UNREGISTER_ABILITY_CATEGORY: {
170
- if ( ! action.slug || ! state[ action.slug ] ) {
164
+ if ( ! state[ action.slug ] ) {
171
165
  return state;
172
166
  }
173
167
  const { [ action.slug ]: _, ...newState } = state;
@@ -6,12 +6,8 @@ import { createSelector } from '@wordpress/data';
6
6
  /**
7
7
  * Internal dependencies
8
8
  */
9
- import type {
10
- Ability,
11
- AbilityCategory,
12
- AbilitiesQueryArgs,
13
- AbilitiesState,
14
- } from '../types';
9
+ import type { Ability, AbilityCategory, AbilitiesQueryArgs } from '../types';
10
+ import type { AbilitiesState } from './types';
15
11
 
16
12
  /**
17
13
  * Returns all registered abilities.
@@ -34,7 +30,7 @@ export const getAbilities = createSelector(
34
30
  }
35
31
  return abilities;
36
32
  },
37
- ( state: AbilitiesState, category?: string ) => [
33
+ ( state: AbilitiesState, { category }: AbilitiesQueryArgs = {} ) => [
38
34
  state.abilitiesByName,
39
35
  category,
40
36
  ]