Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,24 @@ Function used to subscribe to data changes. The listener function is called each
// Subscribe.
const unsubscribe = wp.data.subscribe( () => {
const data = {
slug: wp.data.select( 'core/editor', 'getEditedPostSlug' ),
//Post title
title: wp.data.select( 'core/editor', 'getEditedPostAttribute', 'title' ),
//Post slug
slug: wp.data.select( 'core/editor', 'getEditedPostAttribute', 'slug' ),
//Post type
type: wp.data.select( 'core/editor', 'getEditedPostAttribute', 'type' ),
//Post content
content :wp.data.select( 'core/editor', 'getEditedPostAttribute', 'content' ),
//Number of blocks currently selected
selectedBlockCount: wp.data.select( 'core/editor', 'getSelectedBlockCount' ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Documentation of the data module is meant to be generic. Should we document these selectors as part of the editor module's documentation instead?

Also, in Calypso we have a script to generate selectors documentation automatically, we might be able to adapt it here cc @aduth

};

console.log( 'data changed', data );
//This will log every time data is updated
console.log(data);

} );


// Unsubcribe.
unsubscribe();
```