ably / ably-js

Javascript, Node, Typescript, React, React Native client library SDK for Ably realtime messaging service

Home Page:https://ably.com/download

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

VeskeR opened this issue · 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: #1620 (comment), #1620 (comment) for more info.

┆Issue is synchronized with this Jira Story by Unito

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

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.