{"action":"created","issue":{"url":"https://api.github.com/repos/Urigo/angular-meteor/issues/1443","repository_url":"https://api.github.com/repos/Urigo/angular-meteor","labels_url":"https://api.github.com/repos/Urigo/angular-meteor/issues/1443/labels{/name}","comments_url":"https://api.github.com/repos/Urigo/angular-meteor/issues/1443/comments","events_url":"https://api.github.com/repos/Urigo/angular-meteor/issues/1443/events","html_url":"https://github.com/Urigo/angular-meteor/issues/1443","id":180708873,"number":1443,"title":"problem with subscribe callbacks and ui-router","user":{"login":"mxab","id":1607547,"avatar_url":"https://avatars.githubusercontent.com/u/1607547?v=3","gravatar_id":"","url":"https://api.github.com/users/mxab","html_url":"https://github.com/mxab","followers_url":"https://api.github.com/users/mxab/followers","following_url":"https://api.github.com/users/mxab/following{/other_user}","gists_url":"https://api.github.com/users/mxab/gists{/gist_id}","starred_url":"https://api.github.com/users/mxab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mxab/subscriptions","organizations_url":"https://api.github.com/users/mxab/orgs","repos_url":"https://api.github.com/users/mxab/repos","events_url":"https://api.github.com/users/mxab/events{/privacy}","received_events_url":"https://api.github.com/users/mxab/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-03T18:17:27Z","updated_at":"2016-10-07T19:20:08Z","closed_at":null,"body":"Hi,\r\n\r\nwe are experiencing that subscribe callbacks are not being called when switching from one state to another that initially calls the same subscription.\r\n\r\nFor example let's say two controller have this kind of subscription in their constructor\r\n\r\ncontroller:\r\n```\r\n this.state = \"LOADING...\";\r\n this.subscribe('xxx', ()=>[], (err)=> {\r\n        if (err) {\r\n            console.error(err);\r\n            this.state = \"ERROR\";\r\n        } else {\r\n            this.state = \"READY\";\r\n        }\r\n    });\r\n```\r\n\r\nin the first state this controller works as expected, `this.state` becomes `READY`. When I switch then into the other state the callback never gets called.\r\n\r\nI think it may be the problem that meteor sometimes does not resubscribe if there is already a subscription with the same arguments (none in this case)\r\n\r\nI assume following problem \r\nenter state 1 -> subscribe -> subscribe ready -> entering state 2 -> subscribe (but with same args) -> state1's scope is being destroyed -> autoruns / subscriptions of state1 stop\r\n\r\nI made a `$reactive` free version that also has this issue:\r\n\r\ncontroller:\r\n```\r\nthis.state = \"LOADING...\";\r\nvar c = Meteor.autorun(()=> {\r\n      console.log('Running autorun');\r\n       var sub = Meteor.subscribe('xxx', {\r\n            onReady: ()=> {\r\n                console.log('ready');\r\n                $scope.$apply(()=> {\r\n                    this.state = \"READY\";\r\n                })\r\n            },\r\n            onStop: (err)=> {\r\n                console.log('stopped', err);\r\n                $scope.$apply(()=> {\r\n                    if (err) {\r\n                        console.error(err);\r\n                        this.state = \"ERROR\";\r\n                    } else {\r\n                        this.state = \"STOPPED\";\r\n                    }\r\n                })\r\n            }\r\n        });\r\n    });\r\n$scope.$on('$destroy', ()=> {\r\n        console.log('stopping autorun');\r\n        c.stop();\r\n})\r\n```\r\n\r\nFull running version:\r\nhttps://github.com/mxab/ng-meteor-subscribe-problem\r\n\r\n@Urigo this may not be angular-meteor specific issue but as it is occurring here and not sure if someone else has this issue I opened it here.\r\nI'm really looking forward to get some ideas how to deal with this issue.\r\n\r\nI noticed that ready handler may not get called if the `subscriptionId` of a resulting `subscribe` call stays the, so maybe there should be a check here https://github.com/Urigo/angular-meteor/blob/9bcf2733cd9b5f5acd8f19f6dce283616d7b496b/packages/angular-meteor/src/modules/core.js#L84 if there is already an existing same subscriptionId (or a rerun?) , but I'm not super sure about it.\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Urigo/angular-meteor/issues/comments/252338709","html_url":"https://github.com/Urigo/angular-meteor/issues/1443#issuecomment-252338709","issue_url":"https://api.github.com/repos/Urigo/angular-meteor/issues/1443","id":252338709,"user":{"login":"mxab","id":1607547,"avatar_url":"https://avatars.githubusercontent.com/u/1607547?v=3","gravatar_id":"","url":"https://api.github.com/users/mxab","html_url":"https://github.com/mxab","followers_url":"https://api.github.com/users/mxab/followers","following_url":"https://api.github.com/users/mxab/following{/other_user}","gists_url":"https://api.github.com/users/mxab/gists{/gist_id}","starred_url":"https://api.github.com/users/mxab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mxab/subscriptions","organizations_url":"https://api.github.com/users/mxab/orgs","repos_url":"https://api.github.com/users/mxab/repos","events_url":"https://api.github.com/users/mxab/events{/privacy}","received_events_url":"https://api.github.com/users/mxab/received_events","type":"User","site_admin":false},"created_at":"2016-10-07T19:20:08Z","updated_at":"2016-10-07T19:20:08Z","body":"@Urigo with the chance of being annoying, I think this is actually a really horrible bug that can lead to super strange behaviours (e.g. in our app ;) ). any thoughts/ideas would be really appreciated.\r\n"}}
{"actor":{"display_login":"mxab"}}