{"action":"created","issue":{"url":"https://api.github.com/repos/meteor/meteor/issues/7878","repository_url":"https://api.github.com/repos/meteor/meteor","labels_url":"https://api.github.com/repos/meteor/meteor/issues/7878/labels{/name}","comments_url":"https://api.github.com/repos/meteor/meteor/issues/7878/comments","events_url":"https://api.github.com/repos/meteor/meteor/issues/7878/events","html_url":"https://github.com/meteor/meteor/issues/7878","id":181495153,"number":7878,"title":"New equal subscription instantly ready","user":{"login":"radekmie","id":1379064,"avatar_url":"https://avatars.githubusercontent.com/u/1379064?v=3","gravatar_id":"","url":"https://api.github.com/users/radekmie","html_url":"https://github.com/radekmie","followers_url":"https://api.github.com/users/radekmie/followers","following_url":"https://api.github.com/users/radekmie/following{/other_user}","gists_url":"https://api.github.com/users/radekmie/gists{/gist_id}","starred_url":"https://api.github.com/users/radekmie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/radekmie/subscriptions","organizations_url":"https://api.github.com/users/radekmie/orgs","repos_url":"https://api.github.com/users/radekmie/repos","events_url":"https://api.github.com/users/radekmie/events{/privacy}","received_events_url":"https://api.github.com/users/radekmie/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/meteor/meteor/labels/feature","name":"feature","color":"02d7e1"},{"url":"https://api.github.com/repos/meteor/meteor/labels/Project:DDP","name":"Project:DDP","color":"c7def8"}],"state":"open","locked":false,"assignee":{"login":"tmeasday","id":132554,"avatar_url":"https://avatars.githubusercontent.com/u/132554?v=3","gravatar_id":"","url":"https://api.github.com/users/tmeasday","html_url":"https://github.com/tmeasday","followers_url":"https://api.github.com/users/tmeasday/followers","following_url":"https://api.github.com/users/tmeasday/following{/other_user}","gists_url":"https://api.github.com/users/tmeasday/gists{/gist_id}","starred_url":"https://api.github.com/users/tmeasday/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmeasday/subscriptions","organizations_url":"https://api.github.com/users/tmeasday/orgs","repos_url":"https://api.github.com/users/tmeasday/repos","events_url":"https://api.github.com/users/tmeasday/events{/privacy}","received_events_url":"https://api.github.com/users/tmeasday/received_events","type":"User","site_admin":false},"assignees":[{"login":"tmeasday","id":132554,"avatar_url":"https://avatars.githubusercontent.com/u/132554?v=3","gravatar_id":"","url":"https://api.github.com/users/tmeasday","html_url":"https://github.com/tmeasday","followers_url":"https://api.github.com/users/tmeasday/followers","following_url":"https://api.github.com/users/tmeasday/following{/other_user}","gists_url":"https://api.github.com/users/tmeasday/gists{/gist_id}","starred_url":"https://api.github.com/users/tmeasday/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmeasday/subscriptions","organizations_url":"https://api.github.com/users/tmeasday/orgs","repos_url":"https://api.github.com/users/tmeasday/repos","events_url":"https://api.github.com/users/tmeasday/events{/privacy}","received_events_url":"https://api.github.com/users/tmeasday/received_events","type":"User","site_admin":false}],"milestone":null,"comments":4,"created_at":"2016-10-06T18:47:57Z","updated_at":"2016-10-12T02:18:36Z","closed_at":null,"body":"## TL;DR;\r\n```js\r\n// Now:\r\nMeteor.subscribe('subscription', arg1, arg2, ..., argN, () => {\r\n    Meteor.subscribe('subscription', arg1, arg2, ..., argN).ready(); // false\r\n});\r\n\r\n// Suggested:\r\nMeteor.subscribe('subscription', arg1, arg2, ..., argN, () => {\r\n    Meteor.subscribe('subscription', arg1, arg2, ..., argN).ready(); // true\r\n});\r\n```\r\n\r\n## Background\r\nProbably most of React apps are using [`react-meteor-data`](https://github.com/meteor/react-packages/tree/devel/packages/react-meteor-data) or [`react-komposer`](https://github.com/kadirahq/react-komposer) to subscribe and fetch data. If you were working with one of them, you've probably seen some similar code:\r\n\r\n```js\r\nexport default composer (props, onData) {\r\n    const subscriptionA = Meteor.subscribe('a', props.a);\r\n    const subscriptionB = Meteor.subscribe('b', props.b);\r\n    // More subscriptions\r\n\r\n    if (!subscriptionA.ready() || !subscriptionB.ready()) {\r\n        // Loading state\r\n    }\r\n\r\n    // Ready state\r\n}\r\n```\r\n\r\nNow let's assume, that we are subscribing the same subscriptions with the same parameters in other containers. Even if our _equal_ subscriptions are ready, we have to wait for a DDP `ready` message, so loading state is impossible to be skipped - loader can blink and disappear instantly.\r\n\r\n## Workaround\r\nI've implemented a rough workaround that wraps `Meteor.subscribe` with the following logic:\r\n\r\n0. Subscribe normally.\r\n0. Check if there's already an _equal_ subscription.\r\n0. If there is at least one, mark handle as ready _(same as a DDP `ready` message)_.\r\n0. Return the handle.\r\n\r\nAfter applying it in few projects, some part of views is instantly loaded - loading screens are gone!\r\n\r\n## Problem?\r\nI've dived deeply into the [`ddp-client`](https://github.com/meteor/meteor/blob/devel/packages/ddp-client/) package and even if server rejects our subscription - ex. we can't subscribe after 12AM - being `ready` instantly [is not a problem because `nosub` message will clean subscription gracefully](https://github.com/meteor/meteor/blob/devel/packages/ddp-client/livedata_connection.js#L573-L576).\r\n\r\n## Solution\r\nI want to implement my workaround directly in `Meteor.subscribe`. It will be similar to this [reactive subscriptions mechanism](https://github.com/meteor/meteor/blob/devel/packages/ddp-client/livedata_connection.js#L573-L576) _(but without `sub.inactive`)_.\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/meteor/meteor/issues/comments/253100755","html_url":"https://github.com/meteor/meteor/issues/7878#issuecomment-253100755","issue_url":"https://api.github.com/repos/meteor/meteor/issues/7878","id":253100755,"user":{"login":"tmeasday","id":132554,"avatar_url":"https://avatars.githubusercontent.com/u/132554?v=3","gravatar_id":"","url":"https://api.github.com/users/tmeasday","html_url":"https://github.com/tmeasday","followers_url":"https://api.github.com/users/tmeasday/followers","following_url":"https://api.github.com/users/tmeasday/following{/other_user}","gists_url":"https://api.github.com/users/tmeasday/gists{/gist_id}","starred_url":"https://api.github.com/users/tmeasday/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tmeasday/subscriptions","organizations_url":"https://api.github.com/users/tmeasday/orgs","repos_url":"https://api.github.com/users/tmeasday/repos","events_url":"https://api.github.com/users/tmeasday/events{/privacy}","received_events_url":"https://api.github.com/users/tmeasday/received_events","type":"User","site_admin":false},"created_at":"2016-10-12T02:18:36Z","updated_at":"2016-10-12T02:18:36Z","body":"Sorry to come late to the party here but I think this isn't the right approach. \r\n\r\nHiding the fact that the second identically subscription runs by making it appear insta-ready just obscures what's going on from the developer.\r\n\r\nIn your use-case I would suggest using something like [`subs-manager`](https://atmospherejs.com/meteorhacks/subs-manager) which correctly ensures that you only have one copy of each subscription with a familiar interface.\r\n\r\nAlternatively, we could consider changing `ddp-client` to mirror that behaviour (to only ever have one copy of any identical subscription active). However this is a big change and I'm not sure I can justify it, given that workarounds like `subs-manager` exist."}}
{"actor":{"display_login":"tmeasday"}}