diff --git a/data/README.md b/data/README.md index 74b30566ae6e8a..a77e4f1c0863f4 100644 --- a/data/README.md +++ b/data/README.md @@ -70,13 +70,25 @@ Function used to subscribe to data changes. The listener function is called each ```js // Subscribe. const unsubscribe = wp.data.subscribe( () => { - const data = { - slug: wp.data.select( 'core/editor', 'getEditedPostSlug' ), - }; + const data = { + //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' ), + }; + + //This will log every time data is updated + console.log(data); - console.log( 'data changed', data ); } ); + // Unsubcribe. unsubscribe(); ```