Skip to content

Commit

Permalink
Update wp.data.subscribe docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Shelob9 authored Feb 13, 2018
1 parent f836938 commit 111f160
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
```

0 comments on commit 111f160

Please sign in to comment.