{"action":"created","issue":{"url":"https://api.github.com/repos/firebase/reactfire/issues/66","labels_url":"https://api.github.com/repos/firebase/reactfire/issues/66/labels{/name}","comments_url":"https://api.github.com/repos/firebase/reactfire/issues/66/comments","events_url":"https://api.github.com/repos/firebase/reactfire/issues/66/events","html_url":"https://github.com/firebase/reactfire/issues/66","id":107842756,"number":66,"title":"Provide a way to bind to a props-dependent ref","user":{"login":"jyasskin","id":83420,"avatar_url":"https://avatars.githubusercontent.com/u/83420?v=3","gravatar_id":"","url":"https://api.github.com/users/jyasskin","html_url":"https://github.com/jyasskin","followers_url":"https://api.github.com/users/jyasskin/followers","following_url":"https://api.github.com/users/jyasskin/following{/other_user}","gists_url":"https://api.github.com/users/jyasskin/gists{/gist_id}","starred_url":"https://api.github.com/users/jyasskin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jyasskin/subscriptions","organizations_url":"https://api.github.com/users/jyasskin/orgs","repos_url":"https://api.github.com/users/jyasskin/repos","events_url":"https://api.github.com/users/jyasskin/events{/privacy}","received_events_url":"https://api.github.com/users/jyasskin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/firebase/reactfire/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-09-23T03:25:44Z","updated_at":"2015-10-21T23:15:30Z","closed_at":null,"body":"This has come up in a couple questions (#31, #49, http://stackoverflow.com/q/32688547/943619), so I'm going to attempt to propose an API change to fix it. I'd be totally happy with another solution, of course.\r\n\r\nI want to bind a dynamic Firebase reference to `this.state.foo`. We want to recompute the reference whenever props change (*). If the reference hasn't changed, we don't want any extra network traffic, as seems to happen when `fbref.off(); fbref.on()` are called. If the reference has changed, it'd be nice to avoid the flicker from an intermediate `this.setState({foo: undefined})` as happens in `unbind()`.\r\n\r\nSo, `bindAsObject()` and `bindAsArray()` should accept a function `(props)=>ref` as their first parameter, in addition to the existing `Firebase` ref. (That is, `bindAsX(functionOrRef, name, callback)`.) This should be called at bind time with `this.props`, and again in `componentWillReceiveProps`. If it returns the same ref as the previous call, nothing should happen. If it returns a new ref, ReactFire should unbind from the old reference and bind to the new one. ReactFire should not set the state to undefined while the new data loads, to avoid making the UI jump twice. Optionally, ReactFire should set a \"loading\" state of some sort so the UI can grey-out or otherwise disable the right regions of the component while it's out of date.\r\n\r\n(*) In general, the reference could be dynamic based on both state (especially auth data from #65) and props, but restricting it to props makes sure data only flows in one direction, and state can always(?) be turned into props by nesting an extra level."},"comment":{"url":"https://api.github.com/repos/firebase/reactfire/issues/comments/150050807","html_url":"https://github.com/firebase/reactfire/issues/66#issuecomment-150050807","issue_url":"https://api.github.com/repos/firebase/reactfire/issues/66","id":150050807,"user":{"login":"jwngr","id":4149793,"avatar_url":"https://avatars.githubusercontent.com/u/4149793?v=3","gravatar_id":"","url":"https://api.github.com/users/jwngr","html_url":"https://github.com/jwngr","followers_url":"https://api.github.com/users/jwngr/followers","following_url":"https://api.github.com/users/jwngr/following{/other_user}","gists_url":"https://api.github.com/users/jwngr/gists{/gist_id}","starred_url":"https://api.github.com/users/jwngr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jwngr/subscriptions","organizations_url":"https://api.github.com/users/jwngr/orgs","repos_url":"https://api.github.com/users/jwngr/repos","events_url":"https://api.github.com/users/jwngr/events{/privacy}","received_events_url":"https://api.github.com/users/jwngr/received_events","type":"User","site_admin":false},"created_at":"2015-10-21T23:15:30Z","updated_at":"2015-10-21T23:15:30Z","body":"Sounds like we have something in common :ghost: "}}