{"action":"created","issue":{"url":"https://api.github.com/repos/Reactive-Extensions/RxJS/issues/1052","labels_url":"https://api.github.com/repos/Reactive-Extensions/RxJS/issues/1052/labels{/name}","comments_url":"https://api.github.com/repos/Reactive-Extensions/RxJS/issues/1052/comments","events_url":"https://api.github.com/repos/Reactive-Extensions/RxJS/issues/1052/events","html_url":"https://github.com/Reactive-Extensions/RxJS/issues/1052","id":120675325,"number":1052,"title":"shareReplay triggers subscription when not expected","user":{"login":"jhoguet","id":1234146,"avatar_url":"https://avatars.githubusercontent.com/u/1234146?v=3","gravatar_id":"","url":"https://api.github.com/users/jhoguet","html_url":"https://github.com/jhoguet","followers_url":"https://api.github.com/users/jhoguet/followers","following_url":"https://api.github.com/users/jhoguet/following{/other_user}","gists_url":"https://api.github.com/users/jhoguet/gists{/gist_id}","starred_url":"https://api.github.com/users/jhoguet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jhoguet/subscriptions","organizations_url":"https://api.github.com/users/jhoguet/orgs","repos_url":"https://api.github.com/users/jhoguet/repos","events_url":"https://api.github.com/users/jhoguet/events{/privacy}","received_events_url":"https://api.github.com/users/jhoguet/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-12-07T00:04:02Z","updated_at":"2015-12-16T04:47:28Z","closed_at":null,"body":"I am trying to wrap my head around hot observables, publish, and connect. \r\n\r\nI came across shareReplay which I thought was going to brings things together, but the results are not what I would expect. \r\n\r\nGiven\r\n\r\n```js\r\nvar interval = Rx.Observable.range(1, 2);\r\n\r\nvar source = interval\r\n    .doAction(function (x) {\r\n        console.log(`Side effect ${x}`);\r\n    });\r\n\r\nvar published = source\r\n    .shareReplay(1);\r\n\r\npublished.subscribe(x => console.log(`a ${x}`));\r\npublished.subscribe(x => console.log(`b ${x}`));\r\n```\r\n\r\nI expect the following\r\n```\r\n\"Side effect 1\"\r\n\"a 1\"\r\n\"Side effect 2\"\r\n\"a 2\"\r\n\"b 2\"\r\n```\r\nBut I actually get\r\n```\r\n\"Side effect 1\"\r\n\"a 1\"\r\n\"Side effect 2\"\r\n\"a 2\"\r\n\"b 2\"\r\n\"Side effect 1\"\r\n```\r\nWhy is side effect 1 being called again, especially when it doesn't output 1 to any other subscribers?\r\n\r\nI am sorry if this is something obvious - I am still ramping up on rx. \r\n\r\nhttp://jsbin.com/basufi/edit?js,console,output"},"comment":{"url":"https://api.github.com/repos/Reactive-Extensions/RxJS/issues/comments/164993867","html_url":"https://github.com/Reactive-Extensions/RxJS/issues/1052#issuecomment-164993867","issue_url":"https://api.github.com/repos/Reactive-Extensions/RxJS/issues/1052","id":164993867,"user":{"login":"bouzuya","id":1221346,"avatar_url":"https://avatars.githubusercontent.com/u/1221346?v=3","gravatar_id":"","url":"https://api.github.com/users/bouzuya","html_url":"https://github.com/bouzuya","followers_url":"https://api.github.com/users/bouzuya/followers","following_url":"https://api.github.com/users/bouzuya/following{/other_user}","gists_url":"https://api.github.com/users/bouzuya/gists{/gist_id}","starred_url":"https://api.github.com/users/bouzuya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bouzuya/subscriptions","organizations_url":"https://api.github.com/users/bouzuya/orgs","repos_url":"https://api.github.com/users/bouzuya/repos","events_url":"https://api.github.com/users/bouzuya/events{/privacy}","received_events_url":"https://api.github.com/users/bouzuya/received_events","type":"User","site_admin":false},"created_at":"2015-12-16T04:47:28Z","updated_at":"2015-12-16T04:47:28Z","body":"`s/.from([1, 2, 3])/.interval(1).take(3)/`\r\n\r\n```js\r\nimport { Observable } from 'rx';\r\n\r\nconst observable = Observable\r\n  // .from([1, 2, 3])\r\n  .interval(1).take(3)\r\n  .do(value => console.log(`do: ${value}`))\r\n  .replay(null, 2)\r\n  .refCount();\r\nobservable.subscribe(value => console.log(`observer1 onNext: ${value}`));\r\nconsole.log('observer1 subscribed');\r\nobservable.subscribe(value => console.log(`observer2 onNext: ${value}`));\r\nconsole.log('observer2 subscribed');\r\n// observer1 subscribed\r\n// observer2 subscribed\r\n// do: 0\r\n// observer1 onNext: 0\r\n// observer2 onNext: 0\r\n// do: 1\r\n// observer1 onNext: 1\r\n// observer2 onNext: 1\r\n// do: 2\r\n// observer1 onNext: 2\r\n// observer2 onNext: 2\r\n```"}}