ably-js icon indicating copy to clipboard operation
ably-js copied to clipboard

Decide on renaming `id` field in react-hooks for `AblyProvider` and channel options

Open VeskeR opened this issue 11 months ago • 2 comments

id can be quite misleading in some cases, for example when used like this:

useChannel(
  {
    channelName: 'your-derived-channel-name',
    id: 'rob',
  },
  (message) => {
    updateDerivedChannelMessages((prev) => [...prev, message]);
  }
);

you may think that id here is an id of this channel or something, but in reality it refers to the id used when setting up your AblyProvider and ChannelProvider up in the component tree.

Better alternative would be ablyProviderId, contextId.

See next comments from PR: https://github.com/ably/ably-js/pull/1620#discussion_r1497782783, https://github.com/ably/ably-js/pull/1620#discussion_r1502826007 for more info.

┆Issue is synchronized with this Jira Task by Unito

VeskeR avatar Feb 26 '24 19:02 VeskeR

Copying Slack conversation here: Owen:

i think ablyProviderId sounds fine, although i would maybe argue that it's used for identifying the wrapped realtime client rather than just the provider so on that basis, maybe just ablyId would suit?

Me:

hmm, I see. also, AblyProvider and ChannelProvider both set something on context, but AblyProvider is responsible for providing realtime client, and ChannelProvider is responsible for providing options for channels. and the "id" you use for those providers should match, thus calling it ablyProviderId might be a bit too specific there is also an option to call it contextId, or ablyContextId

Owen:

i like ablyContextId more than ablyProviderId

VeskeR avatar Feb 27 '24 16:02 VeskeR

ablyId and ablyContextId both sound good and should prevent people from thinking that this "id" is related to a channel, instead of provider components. So we decided to go with shorter variant ablyId.

VeskeR avatar Feb 27 '24 16:02 VeskeR

Done in https://github.com/ably/ably-js/pull/1676

VeskeR avatar Mar 11 '24 12:03 VeskeR