Skip to content

Commit 2fa3d3d

Browse files
authored
Tooling: Improve docs build to consider memoized selectors (#9756)
1 parent f5338ed commit 2fa3d3d

6 files changed

Lines changed: 374 additions & 20 deletions

File tree

docs/data/data-core-blocks.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
## Selectors
44

5+
### getBlockTypes
6+
7+
Returns all the available block types.
8+
9+
*Parameters*
10+
11+
* state: Data state.
12+
513
### getBlockType
614

715
Returns a block type by name.
@@ -11,6 +19,10 @@ Returns a block type by name.
1119
* state: Data state.
1220
* name: Block type name.
1321

22+
*Returns*
23+
24+
Block Type.
25+
1426
### getCategories
1527

1628
Returns all the available categories.
@@ -47,6 +59,32 @@ Returns the name of the fallback block name.
4759

4860
Fallback block name.
4961

62+
### getChildBlockNames
63+
64+
Returns an array with the child blocks of a given block.
65+
66+
*Parameters*
67+
68+
* state: Data state.
69+
* blockName: Block type name.
70+
71+
*Returns*
72+
73+
Array of child block names.
74+
75+
### hasChildBlocks
76+
77+
Returns a boolean indicating if a block has child blocks or not.
78+
79+
*Parameters*
80+
81+
* state: Data state.
82+
* blockName: Block type name.
83+
84+
*Returns*
85+
86+
True if a block contains child blocks and false otherwise.
87+
5088
## Actions
5189

5290
### addBlockTypes

docs/data/data-core-edit-post.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ Returns the state of legacy meta boxes.
167167

168168
State of meta box at specified location.
169169

170+
### hasMetaBoxes
171+
172+
Returns true if the post is using Meta Boxes
173+
174+
*Parameters*
175+
176+
* state: Global application state
177+
178+
*Returns*
179+
180+
Whether there are metaboxes or not.
181+
170182
### isSavingMetaBoxes
171183

172184
Returns true if the Meta Boxes are being saved.

docs/data/data-core-editor.md

Lines changed: 209 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,25 @@ unsaved status values.
320320

321321
Whether the post has been published.
322322

323+
### getBlockDependantsCacheBust
324+
325+
Returns a new reference when the inner blocks of a given block client ID
326+
change. This is used exclusively as a memoized selector dependant, relying
327+
on this selector's shared return value and recursively those of its inner
328+
blocks defined as dependencies. This abuses mechanics of the selector
329+
memoization to return from the original selector function only when
330+
dependants change.
331+
332+
*Parameters*
333+
334+
* state: Editor state.
335+
* clientId: Block client ID.
336+
337+
*Returns*
338+
339+
A value whose reference will change only when inner blocks of
340+
the given block client ID change.
341+
323342
### getBlockName
324343

325344
Returns a block's name given its client ID, or null if no block exists with
@@ -334,6 +353,80 @@ the client ID.
334353

335354
Block name.
336355

356+
### getBlock
357+
358+
Returns a block given its client ID. This is a parsed copy of the block,
359+
containing its `blockName`, `clientId`, and current `attributes` state. This
360+
is not the block's registration settings, which must be retrieved from the
361+
blocks module registration store.
362+
363+
*Parameters*
364+
365+
* state: Editor state.
366+
* clientId: Block client ID.
367+
368+
*Returns*
369+
370+
Parsed block object.
371+
372+
### getBlocks
373+
374+
Returns all block objects for the current post being edited as an array in
375+
the order they appear in the post.
376+
377+
Note: It's important to memoize this selector to avoid return a new instance
378+
on each call
379+
380+
*Parameters*
381+
382+
* state: Editor state.
383+
* rootClientId: Optional root client ID of block list.
384+
385+
*Returns*
386+
387+
Post blocks.
388+
389+
### getClientIdsWithDescendants
390+
391+
Returns an array containing the clientIds of the top-level blocks
392+
and their descendants of any depth (for nested blocks).
393+
394+
*Parameters*
395+
396+
* state: Global application state.
397+
398+
*Returns*
399+
400+
ids of top-level and descendant blocks.
401+
402+
### getGlobalBlockCount
403+
404+
Returns the total number of blocks, or the total number of blocks with a specific name in a post.
405+
The number returned includes nested blocks.
406+
407+
*Parameters*
408+
409+
* state: Global application state.
410+
* blockName: Optional block name, if specified only blocks of that type will be counted.
411+
412+
*Returns*
413+
414+
Number of blocks in the post, or number of blocks with name equal to blockName.
415+
416+
### getBlocksByClientId
417+
418+
Given an array of block client IDs, returns the corresponding array of block
419+
objects.
420+
421+
*Parameters*
422+
423+
* state: Editor state.
424+
* clientIds: Client IDs for which blocks are to be returned.
425+
426+
*Returns*
427+
428+
Block objects.
429+
337430
### getBlockCount
338431

339432
Returns the number of blocks currently present in the post.
@@ -503,6 +596,32 @@ This position is to used to position the caret properly when the selected block
503596

504597
Selected block.
505598

599+
### getMultiSelectedBlockClientIds
600+
601+
Returns the current multi-selection set of block client IDs, or an empty
602+
array if there is no multi-selection.
603+
604+
*Parameters*
605+
606+
* state: Editor state.
607+
608+
*Returns*
609+
610+
Multi-selected block client IDs.
611+
612+
### getMultiSelectedBlocks
613+
614+
Returns the current multi-selection set of blocks, or an empty array if
615+
there is no multi-selection.
616+
617+
*Parameters*
618+
619+
* state: Editor state.
620+
621+
*Returns*
622+
623+
Multi-selected block objects.
624+
506625
### getFirstMultiSelectedBlockClientId
507626

508627
Returns the client ID of the first block in the multi-selection set, or null
@@ -558,6 +677,21 @@ false otherwise.
558677

559678
Whether block is in multi-selection set.
560679

680+
### isAncestorMultiSelected
681+
682+
Returns true if an ancestor of the block is multi-selected, or false
683+
otherwise.
684+
685+
*Parameters*
686+
687+
* state: Editor state.
688+
* clientId: Block client ID.
689+
690+
*Returns*
691+
692+
Whether an ancestor of the block is in multi-selection
693+
set.
694+
561695
### getMultiSelectedBlocksStartClientId
562696

563697
Returns the client ID of the block which begins the multi-selection set, or
@@ -855,6 +989,19 @@ default post format. Returns null if the format cannot be determined.
855989

856990
Suggested post format.
857991

992+
### getEditedPostContent
993+
994+
Returns the content of the post being edited, preferring raw string edit
995+
before falling back to serialization of block state.
996+
997+
*Parameters*
998+
999+
* state: Global application state.
1000+
1001+
*Returns*
1002+
1003+
Post content.
1004+
8581005
### getNotices
8591006

8601007
Returns the user notices array.
@@ -867,6 +1014,67 @@ Returns the user notices array.
8671014

8681015
List of notices.
8691016

1017+
### canInsertBlockType
1018+
1019+
Determines if the given block type is allowed to be inserted, and, if
1020+
parentClientId is provided, whether it is allowed to be nested within the
1021+
given parent.
1022+
1023+
*Parameters*
1024+
1025+
* state: Editor state.
1026+
* blockName: The name of the given block type, e.g.
1027+
'core/paragraph'.
1028+
* parentClientId: The parent that the given block is to be
1029+
nested within, or null.
1030+
1031+
*Returns*
1032+
1033+
Whether the given block type is allowed to be inserted.
1034+
1035+
### getInserterItems
1036+
1037+
Determines the items that appear in the inserter. Includes both static
1038+
items (e.g. a regular block type) and dynamic items (e.g. a reusable block).
1039+
1040+
Each item object contains what's necessary to display a button in the
1041+
inserter and handle its selection.
1042+
1043+
The 'utility' property indicates how useful we think an item will be to the
1044+
user. There are 4 levels of utility:
1045+
1046+
1. Blocks that are contextually useful (utility = 3)
1047+
2. Blocks that have been previously inserted (utility = 2)
1048+
3. Blocks that are in the common category (utility = 1)
1049+
4. All other blocks (utility = 0)
1050+
1051+
The 'frecency' property is a heuristic (https://en.wikipedia.org/wiki/Frecency)
1052+
that combines block usage frequenty and recency.
1053+
1054+
Items are returned ordered descendingly by their 'utility' and 'frecency'.
1055+
1056+
*Parameters*
1057+
1058+
* state: Editor state.
1059+
* parentClientId: The block we are inserting into, if any.
1060+
1061+
*Returns*
1062+
1063+
Items that appear in inserter.
1064+
1065+
### getReusableBlock
1066+
1067+
Returns the reusable block with the given ID.
1068+
1069+
*Parameters*
1070+
1071+
* state: Global application state.
1072+
* ref: The reusable block's ID.
1073+
1074+
*Returns*
1075+
1076+
The reusable block, or null if none exists.
1077+
8701078
### isSavingReusableBlock
8711079

8721080
Returns whether or not the reusable block with the given ID is being saved.
@@ -1411,4 +1619,4 @@ Returns an action object used in signalling that the editor settings have been u
14111619

14121620
*Parameters*
14131621

1414-
* settings: Updated settings
1622+
* settings: Updated settings

docs/data/data-core-nux.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
## Selectors
44

5+
### getAssociatedGuide
6+
7+
Returns an object describing the guide, if any, that the given tip is a part
8+
of.
9+
10+
*Parameters*
11+
12+
* state: Global application state.
13+
* tipId: The tip to query.
14+
515
### isTipVisible
616

717
Determines whether or not the given tip is showing. Tips are hidden if they
@@ -13,6 +23,10 @@ guide that they have been added to.
1323
* state: Global application state.
1424
* tipId: The tip to query.
1525

26+
*Returns*
27+
28+
Whether or not the given tip is showing.
29+
1630
### areTipsEnabled
1731

1832
Returns whether or not tips are globally enabled.

docs/data/data-core.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@ Returns all available authors.
2424

2525
Authors list.
2626

27+
### getUserQueryResults
28+
29+
Returns all the users returned by a query ID.
30+
31+
*Parameters*
32+
33+
* state: Data state.
34+
* queryID: Query ID.
35+
36+
*Returns*
37+
38+
Users list.
39+
2740
### getEntitiesByKind
2841

2942
Returns whether the entities for the give kind are loaded.

0 commit comments

Comments
 (0)