{"action":"created","issue":{"url":"https://api.github.com/repos/Pauan/rust-dominator/issues/3","repository_url":"https://api.github.com/repos/Pauan/rust-dominator","labels_url":"https://api.github.com/repos/Pauan/rust-dominator/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/Pauan/rust-dominator/issues/3/comments","events_url":"https://api.github.com/repos/Pauan/rust-dominator/issues/3/events","html_url":"https://github.com/Pauan/rust-dominator/issues/3","id":301983444,"number":3,"title":"Multi-Consumer Signals","user":{"login":"davidhewitt","id":1939362,"avatar_url":"https://avatars3.githubusercontent.com/u/1939362?v=4","gravatar_id":"","url":"https://api.github.com/users/davidhewitt","html_url":"https://github.com/davidhewitt","followers_url":"https://api.github.com/users/davidhewitt/followers","following_url":"https://api.github.com/users/davidhewitt/following{/other_user}","gists_url":"https://api.github.com/users/davidhewitt/gists{/gist_id}","starred_url":"https://api.github.com/users/davidhewitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidhewitt/subscriptions","organizations_url":"https://api.github.com/users/davidhewitt/orgs","repos_url":"https://api.github.com/users/davidhewitt/repos","events_url":"https://api.github.com/users/davidhewitt/events{/privacy}","received_events_url":"https://api.github.com/users/davidhewitt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-03-03T09:23:09Z","updated_at":"2018-03-03T10:32:35Z","closed_at":null,"author_association":"NONE","body":"While I was playing around with creating a store struct for state I noticed that only one signal reciever gets the update (I hadn't really grokked this before). E.g.\r\n\r\n    let (sender_text, receiver_text) = signal::unsync::mutable(String::from(\"Hello  \"));\r\n\r\n    html!(\"div\", {\r\n        children(&mut [\r\n            text(\"First: \"),\r\n            text(receiver_text.clone().dynamic()),\r\n            text(\", Second: \"),\r\n            text(receiver_text.clone().dynamic()),\r\n            html!(\"button\", {\r\n                children(&mut [text(\"Click Me!\")]);\r\n                event(move |_: ClickEvent| { sender_text.set(String::from(\"World\")); });\r\n            })\r\n        ]);\r\n    })\r\n\r\nThe rendered Dom populates the text after First: with \"Hello\", but then when the button is clicked it's the second text that recieves \"World\". Ouch 😨 \r\n\r\nI guess that either:\r\n - This is an argument that receivers should not impl Clone.\r\n - I'm doing bad stuff that users shouldn't do.\r\n - Signals should be able to broadcast to multiple receivers.\r\n\r\nI have a concept on how I would build that last one, would it be interesting if I made a PR with a signal::mpmc module to discuss?"},"comment":{"url":"https://api.github.com/repos/Pauan/rust-dominator/issues/comments/370137331","html_url":"https://github.com/Pauan/rust-dominator/issues/3#issuecomment-370137331","issue_url":"https://api.github.com/repos/Pauan/rust-dominator/issues/3","id":370137331,"user":{"login":"Pauan","id":97238,"avatar_url":"https://avatars2.githubusercontent.com/u/97238?v=4","gravatar_id":"","url":"https://api.github.com/users/Pauan","html_url":"https://github.com/Pauan","followers_url":"https://api.github.com/users/Pauan/followers","following_url":"https://api.github.com/users/Pauan/following{/other_user}","gists_url":"https://api.github.com/users/Pauan/gists{/gist_id}","starred_url":"https://api.github.com/users/Pauan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pauan/subscriptions","organizations_url":"https://api.github.com/users/Pauan/orgs","repos_url":"https://api.github.com/users/Pauan/repos","events_url":"https://api.github.com/users/Pauan/events{/privacy}","received_events_url":"https://api.github.com/users/Pauan/received_events","type":"User","site_admin":false},"created_at":"2018-03-03T10:32:35Z","updated_at":"2018-03-03T10:32:35Z","author_association":"OWNER","body":"Yes, Signals are fundamentally designed around a 1 producer 1 consumer model, just like Futures and Streams. This is very important to ensure that they are *zero-cost*. Requiring full broadcast ability for *all* Signals would incur extra expense.\r\n\r\nMost of the time having a 1:1 model works perfectly fine, but as you said sometimes you need a 1:N model, with multiple consumers.\r\n\r\nMy plan is to create a `.shared()` / `.broadcast()` method which can be used on *all* Signals. It returns a new Signal, and that new Signal can be cloned, and the clones receive the same messages. I just haven't had the time to make it yet.\r\n\r\nYou're right that it is confusing to have `Receiver` implement `Clone`, since this behavior is surprising.\r\n\r\nA pull request is welcome, especially if it's an initial sketch that we can discuss, since I have some ideas on how to implement it as well."}}
{"actor":{"display_login":"Pauan"}}