{"action":"created","issue":{"url":"https://api.github.com/repos/paldepind/flyd/issues/8","labels_url":"https://api.github.com/repos/paldepind/flyd/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/paldepind/flyd/issues/8/comments","events_url":"https://api.github.com/repos/paldepind/flyd/issues/8/events","html_url":"https://github.com/paldepind/flyd/issues/8","id":69999551,"number":8,"title":"switchOnNext","user":{"login":"ccorcos","id":1794527,"avatar_url":"https://avatars.githubusercontent.com/u/1794527?v=3","gravatar_id":"","url":"https://api.github.com/users/ccorcos","html_url":"https://github.com/ccorcos","followers_url":"https://api.github.com/users/ccorcos/followers","following_url":"https://api.github.com/users/ccorcos/following{/other_user}","gists_url":"https://api.github.com/users/ccorcos/gists{/gist_id}","starred_url":"https://api.github.com/users/ccorcos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ccorcos/subscriptions","organizations_url":"https://api.github.com/users/ccorcos/orgs","repos_url":"https://api.github.com/users/ccorcos/repos","events_url":"https://api.github.com/users/ccorcos/events{/privacy}","received_events_url":"https://api.github.com/users/ccorcos/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/paldepind/flyd/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":25,"created_at":"2015-04-22T02:07:54Z","updated_at":"2015-05-08T10:38:59Z","closed_at":null,"body":"I must say, I like the simplicity of this library.\r\n\r\nSome functions that I think are missing are [`takeUntil`](http://reactivex.io/documentation/operators/takeuntil.html) and [`switchOnNext`](http://reactivex.io/documentation/operators/switch.html)\r\n\r\nSuppose you are dragging an element. Its helpful to cleanup streams when they're done being used with `take` and `takeUntil`.\r\n\r\n```js\r\nmouseDowns = flyd.stream()\r\n$('body').addEventListener('mousedown', mouseDowns);\r\nmouseDowns.map (e) ->\r\n  elem - $(e.target)\r\n  mouseMoves = flyd.stream()\r\n  $('body').addEventListener('mousemove', mouseMoves);\r\n  mouseUps = flyd.stream().take(1)\r\n  $('body').addEventListener('mouseup', mouseUps);\r\n  mouseMoves.takeUntil(mouseUps).map (e) ->\r\n    elem.css('translateX', e.pageX)\r\n```"},"comment":{"url":"https://api.github.com/repos/paldepind/flyd/issues/comments/100187607","html_url":"https://github.com/paldepind/flyd/issues/8#issuecomment-100187607","issue_url":"https://api.github.com/repos/paldepind/flyd/issues/8","id":100187607,"user":{"login":"ccorcos","id":1794527,"avatar_url":"https://avatars.githubusercontent.com/u/1794527?v=3","gravatar_id":"","url":"https://api.github.com/users/ccorcos","html_url":"https://github.com/ccorcos","followers_url":"https://api.github.com/users/ccorcos/followers","following_url":"https://api.github.com/users/ccorcos/following{/other_user}","gists_url":"https://api.github.com/users/ccorcos/gists{/gist_id}","starred_url":"https://api.github.com/users/ccorcos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ccorcos/subscriptions","organizations_url":"https://api.github.com/users/ccorcos/orgs","repos_url":"https://api.github.com/users/ccorcos/repos","events_url":"https://api.github.com/users/ccorcos/events{/privacy}","received_events_url":"https://api.github.com/users/ccorcos/received_events","type":"User","site_admin":false},"created_at":"2015-05-08T10:38:59Z","updated_at":"2015-05-08T10:38:59Z","body":"I just realized the problem with not ending the stream and letting garbage collection take care of it... In `createMessageStream`, you are likely creating a subscription to the server that ends when the stream ends (remember the stuff with autorun?). If we don't end the stream and let the garbage collector cleanup the stream, then we are left with a subscription to the server that is never stopped..."}}