{"action":"closed","issue":{"url":"https://api.github.com/repos/box/t3js/issues/149","repository_url":"https://api.github.com/repos/box/t3js","labels_url":"https://api.github.com/repos/box/t3js/issues/149/labels{/name}","comments_url":"https://api.github.com/repos/box/t3js/issues/149/comments","events_url":"https://api.github.com/repos/box/t3js/issues/149/events","html_url":"https://github.com/box/t3js/issues/149","id":129094423,"number":149,"title":"emit to a single module instead of broadcasting","user":{"login":"Tsur","id":3246153,"avatar_url":"https://avatars.githubusercontent.com/u/3246153?v=3","gravatar_id":"","url":"https://api.github.com/users/Tsur","html_url":"https://github.com/Tsur","followers_url":"https://api.github.com/users/Tsur/followers","following_url":"https://api.github.com/users/Tsur/following{/other_user}","gists_url":"https://api.github.com/users/Tsur/gists{/gist_id}","starred_url":"https://api.github.com/users/Tsur/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Tsur/subscriptions","organizations_url":"https://api.github.com/users/Tsur/orgs","repos_url":"https://api.github.com/users/Tsur/repos","events_url":"https://api.github.com/users/Tsur/events{/privacy}","received_events_url":"https://api.github.com/users/Tsur/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-01-27T10:12:13Z","updated_at":"2016-03-01T17:57:17Z","closed_at":"2016-03-01T17:57:17Z","body":"Hi guys,\r\n\r\nthis is just a question issue about having different instances of the same module and trying to emit an event to an specific instance instead of broadcasting it to all running instances. A way to do it could be achieved by matching the `module` and the event data in the `context.broadcast` method with an identifier so it would be possible to ensure than a broadcast is actually sent to an specific instance but not to all of then (which makes it not to actually be a \"broadcast\"), but it adds extra work. Let me give you an example. \r\n\r\n```html\r\n<div data-module=\"foo\" data-id=\"1\" />\r\n<div data-module=\"foo\" data-id=\"2\" />\r\n<div data-module=\"bar\" />\r\n```\r\n\r\n```js\r\nApplication.addModule('foo', function(context) {\r\n   \r\n    const MODULE_ID = context.getElement().dataset.id;\r\n\r\n    return {\r\n        messages: [\"helloFoo\"],\r\n        onmessage: (name, data) => {\r\n          \r\n            if(!data.id || data.id === MODULE_ID) console.log(data.text);\r\n\r\n        },\r\n        init: function() {\r\n            console.log('foo');\r\n        }\r\n    };\r\n});\r\n```\r\n\r\n```js\r\nApplication.addModule('bar', function(context) {\r\n    return {\r\n        init: function() {\r\n           \r\n           // Send to just foo module with id 1\r\n            context.broadcast('helloFoo', {text:'helloFoo', id: \"1\"});\r\n\r\n          // Send to just foo module with id 2\r\n            context.broadcast('helloFoo', {text:'helloFoo', id: \"2\"});\r\n\r\n         // Send to all foo modules\r\n            context.broadcast('helloFoo', {text:'helloFoo'});\r\n        }\r\n    };\r\n});\r\n```\r\n\r\nother possible way could be this ...\r\n\r\n\r\n```js\r\nApplication.addModule('foo', function(context) {\r\n   \r\n    const MODULE_ID = context.getElement().dataset.id;\r\n\r\n    return {\r\n        messages: [\"helloFoo.1\", \"helloFoo.2\"],\r\n        onmessage: (name, data) => {\r\n          \r\n           let [name, id] = name.split('.');\r\n\r\n            if(!id || id === MODULE_ID) console.log(data.text);\r\n\r\n        },\r\n        init: function() {\r\n            console.log('foo');\r\n        }\r\n    };\r\n});\r\n```\r\n\r\n```js\r\nApplication.addModule('bar', function(context) {\r\n    return {\r\n        init: function() {\r\n           \r\n           // Send to just foo module with id 1\r\n            context.broadcast('helloFoo.1', {text:'helloFoo'});\r\n\r\n          // Send to just foo module with id 2\r\n            context.broadcast('helloFoo.2', {text:'helloFoo'});\r\n\r\n         // Send to all foo modules\r\n            context.broadcast('helloFoo', {text:'helloFoo'});\r\n        }\r\n    };\r\n});\r\n```\r\n\r\nSorry guys if I'm missing some basic stuff here, but there's a way to do it  without having to worry about ids, some emit method instead of a broadcast, how do you guys manage this stuff ? or is this approach totally wrong and should it be managed by stopping and starting modules ?\r\n\r\nThanks so much"}}