{"action":"created","issue":{"url":"https://api.github.com/repos/WordPress/gutenberg/issues/5012","repository_url":"https://api.github.com/repos/WordPress/gutenberg","labels_url":"https://api.github.com/repos/WordPress/gutenberg/issues/5012/labels{/name}","comments_url":"https://api.github.com/repos/WordPress/gutenberg/issues/5012/comments","events_url":"https://api.github.com/repos/WordPress/gutenberg/issues/5012/events","html_url":"https://github.com/WordPress/gutenberg/issues/5012","id":296539508,"number":5012,"title":"API for Inter-block communication","user":{"login":"Shelob9","id":1994311,"avatar_url":"https://avatars0.githubusercontent.com/u/1994311?v=4","gravatar_id":"","url":"https://api.github.com/users/Shelob9","html_url":"https://github.com/Shelob9","followers_url":"https://api.github.com/users/Shelob9/followers","following_url":"https://api.github.com/users/Shelob9/following{/other_user}","gists_url":"https://api.github.com/users/Shelob9/gists{/gist_id}","starred_url":"https://api.github.com/users/Shelob9/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Shelob9/subscriptions","organizations_url":"https://api.github.com/users/Shelob9/orgs","repos_url":"https://api.github.com/users/Shelob9/repos","events_url":"https://api.github.com/users/Shelob9/events{/privacy}","received_events_url":"https://api.github.com/users/Shelob9/received_events","type":"User","site_admin":false},"labels":[{"id":631490822,"url":"https://api.github.com/repos/WordPress/gutenberg/labels/Extensibility","name":"Extensibility","color":"655104","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2018-02-12T21:59:47Z","updated_at":"2018-02-15T15:19:11Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"I made this trivial example of how two blocks can communicate between each other. https://gitlab.com/caldera-labs/gutenberg-examples/ex-6-counter It is Redux's counter example in WordPress.\r\n\r\n@gziolo asked me to open an issue with use cases where plugin developers need to subscribe to changes in the editor or subscribe to changes in each other's state. We [discussed it here](https://wordpress.slack.com/archives/C02QB2JS7/p1518427215000345) \r\n\r\nSpecifically @gziolo said:\r\n>The only limitation with the way you dispatch actions as you did is that you don’t have access to other modules. That’s why I raised it. I think we need a high level API which will allow to do some actions programmatically. I guess someone needs to provide a valid use case first \r\n\r\nI gave the example of a client site I had that needed to populate WooCommerce's metabox with data from an API lookup based on one field's value. I used jQuery.on() and jQuery.val() a lot on that job. With Gutenberg, it would be crazy for me as a plugin developer to use the DOM as the single source of truth for state. I want to subscribe to state through `wp.data`, which I can.\r\n\r\nAnother example would be if we had a custom block for information about a musical artist. We might also want to develop a custom block that extended the default SoundCloud block, but had a subscription to the artist block. We'd want our extended SoundCloud block to update to a playlist of that artist, if the custom artist block existed.\r\n\r\nRelationships between posts of different types -- books to authors -- is something that plugins like Pods or Posts 2 Posts do. The UI is tricky, since you really want to edit two posts at once. In the author metabox of the books post type, you should be able to select and edit existing authors and create new authors.\r\n\r\nWith Gutenberg, I'd like to be able to develop a set of blocks for books and a set of blocks for authors. The set of blocks I'm building for books will need to include an author block, I'd like to use the same components to construct the book author block as I do constructing the blocks I need for the author post type.\r\n\r\nAs a plugin developer I need an API that provides for inter-block communication and is consistently shaped no matter which of these two contexts I'm in. Also, once this API is well defined, I can use it with other instances of `wp.data` or of Redux, which makes my components potentially useful in the front-end, which is where this gets even more fun :)\r\n\r\n\r\nRelated for context:\r\n* https://wordpress.org/gutenberg/handbook/extensibility/\r\n* https://github.com/WordPress/gutenberg/tree/master/data\r\n* https://github.com/reactjs/redux/tree/master/examples/counter\r\n* https://gitlab.com/caldera-labs/gutenberg-examples/ex-6-counter\r\n* #3330 \r\n* #5006\r\n"},"comment":{"url":"https://api.github.com/repos/WordPress/gutenberg/issues/comments/365958588","html_url":"https://github.com/WordPress/gutenberg/issues/5012#issuecomment-365958588","issue_url":"https://api.github.com/repos/WordPress/gutenberg/issues/5012","id":365958588,"user":{"login":"JasonHoffmann","id":1718298,"avatar_url":"https://avatars0.githubusercontent.com/u/1718298?v=4","gravatar_id":"","url":"https://api.github.com/users/JasonHoffmann","html_url":"https://github.com/JasonHoffmann","followers_url":"https://api.github.com/users/JasonHoffmann/followers","following_url":"https://api.github.com/users/JasonHoffmann/following{/other_user}","gists_url":"https://api.github.com/users/JasonHoffmann/gists{/gist_id}","starred_url":"https://api.github.com/users/JasonHoffmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JasonHoffmann/subscriptions","organizations_url":"https://api.github.com/users/JasonHoffmann/orgs","repos_url":"https://api.github.com/users/JasonHoffmann/repos","events_url":"https://api.github.com/users/JasonHoffmann/events{/privacy}","received_events_url":"https://api.github.com/users/JasonHoffmann/received_events","type":"User","site_admin":false},"created_at":"2018-02-15T15:19:11Z","updated_at":"2018-02-15T15:19:11Z","author_association":"NONE","body":"I'm still a bit unclear about how to use `wp.data` to allow _other_ plugins to hook into wp.data and change something.\r\n\r\nI've posted a gist of what I'm working on, which is a pretty basic Syntax Highlighting block. I have a list of languages that would be available but I'd want other plugins to be able to register their own to the array if they wanted to add one:\r\nhttps://gist.github.com/JasonHoffmann/31a492aaf6f3b244b9e32ce1fe8526c9\r\n\r\n`index.js` is a simplified version of the main block and `addon.js` is a sample implementation that would be added inside of another plugin. It's using `wp.hooks` but would there be a way to replicate this with `wp.data`. I'm not sure if it would be possible for the `addon.js` file to register it's own reducer and somehow return a mutated state. But I know that `addon.js` would not be able to dispatch an action on an existing reducer, since it would have no access to it unless I made that globally available. Am I missing something?"}}
{"actor":{"display_login":"JasonHoffmann"}}