Skip to content

Commit

Permalink
Rename Abstract* classes to *Interface
Browse files Browse the repository at this point in the history
I _think_ that this reads better, now that as of 7392200 they’re no
longer classes. Admittedly there’s now an inconsistency in that these
are the only interfaces with `Interface` in their name (we need
something distinguishing in their name, per d246033), but I think it’d
be better to live with it rather than to make the name of all of our
types longer.
  • Loading branch information
lawrence-forooghian committed Dec 4, 2023
1 parent 7392200 commit 2d0aa6a
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 28 deletions.
12 changes: 6 additions & 6 deletions ably.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

import {
AbstractRest,
RestInterface,
ClientOptions,
Crypto,
MessageStatic,
PresenceMessageStatic,
AbstractRealtime,
RealtimeInterface,
Auth,
Channels,
Channel,
Expand All @@ -31,7 +31,7 @@ import {
/**
* A client that offers a simple stateless API to interact directly with Ably's REST API.
*/
export declare class Rest implements AbstractRest {
export declare class Rest implements RestInterface {
/**
* Construct a client object using an Ably {@link ClientOptions} object.
*
Expand All @@ -57,7 +57,7 @@ export declare class Rest implements AbstractRest {
*/
static PresenceMessage: PresenceMessageStatic;

// Requirements of AbstractRest
// Requirements of RestInterface

auth: Auth;
channels: Channels<Channel>;
Expand All @@ -82,7 +82,7 @@ export declare class Rest implements AbstractRest {
/**
* A client that extends the functionality of {@link Rest} and provides additional realtime-specific features.
*/
export declare class Realtime implements AbstractRealtime {
export declare class Realtime implements RealtimeInterface {
/**
* Construct a client object using an Ably {@link ClientOptions} object.
*
Expand All @@ -108,7 +108,7 @@ export declare class Realtime implements AbstractRealtime {
*/
static PresenceMessage: PresenceMessageStatic;

// Requirements of AbstractRealtime
// Requirements of RealtimeInterface

clientId: string;
close(): void;
Expand Down
12 changes: 6 additions & 6 deletions modules.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ErrorInfo } from './ably';
import {
AbstractRest,
RestInterface,
ClientOptions,
Crypto as CryptoClass,
MessageStatic,
PresenceMessageStatic,
AbstractRealtime,
RealtimeInterface,
Auth,
Channels,
Channel,
Expand Down Expand Up @@ -266,7 +266,7 @@ export interface ModulesMap {
*
* `BaseRest` is the equivalent, in the modular variant of the Ably Client Library SDK, of the [`Rest`](../../default/classes/Rest.html) class in the default variant of the SDK. The difference is that its constructor allows you to decide exactly which functionality the client should include. This allows unused functionality to be tree-shaken, reducing bundle size.
*/
export declare class BaseRest implements AbstractRest {
export declare class BaseRest implements RestInterface {
/**
* Construct a client object using an Ably {@link ClientOptions} object.
*
Expand All @@ -279,7 +279,7 @@ export declare class BaseRest implements AbstractRest {
*/
constructor(options: ClientOptions, modules: ModulesMap);

// Requirements of AbstractRest
// Requirements of RestInterface

auth: Auth;
channels: Channels<Channel>;
Expand Down Expand Up @@ -307,7 +307,7 @@ export declare class BaseRest implements AbstractRest {
*
* `BaseRealtime` is the equivalent, in the modular variant of the Ably Client Library SDK, of the [`Realtime`](../../default/classes/Realtime.html) class in the default variant of the SDK. The difference is that its constructor allows you to decide exactly which functionality the client should include. This allows unused functionality to be tree-shaken, reducing bundle size.
*/
export declare class BaseRealtime implements AbstractRealtime {
export declare class BaseRealtime implements RealtimeInterface {
/**
* Construct a client object using an Ably {@link ClientOptions} object.
*
Expand All @@ -321,7 +321,7 @@ export declare class BaseRealtime implements AbstractRealtime {
*/
constructor(options: ClientOptions, modules: ModulesMap);

// Requirements of AbstractRealtime
// Requirements of RealtimeInterface

clientId: string;
close(): void;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/react-hooks/src/AblyProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ const canUseSymbol = typeof Symbol === 'function' && typeof Symbol.for === 'func

interface AblyProviderProps {
children?: React.ReactNode | React.ReactNode[] | null;
client?: Ably.Ably.AbstractRealtime;
client?: Ably.Ably.RealtimeInterface;
id?: string;
}

type AblyContextType = React.Context<Ably.AbstractRealtime>;
type AblyContextType = React.Context<Ably.RealtimeInterface>;

// An object is appended to `React.createContext` which stores all contexts
// indexed by id, which is used by useAbly to find the correct context when an
Expand Down
4 changes: 2 additions & 2 deletions src/platform/react-hooks/src/hooks/useAbly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from 'react';
import { getContext } from '../AblyProvider.js';
import * as API from '../../../../../ably.js';

export function useAbly(id = 'default'): API.AbstractRealtime {
const client = React.useContext(getContext(id)) as API.AbstractRealtime;
export function useAbly(id = 'default'): API.RealtimeInterface {
const client = React.useContext(getContext(id)) as API.RealtimeInterface;

if (!client) {
throw new Error(
Expand Down
4 changes: 2 additions & 2 deletions src/platform/react-hooks/src/hooks/useChannel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { act } from 'react-dom/test-utils';
import { AblyProvider } from '../AblyProvider.js';

function renderInCtxProvider(client: FakeAblySdk, children: React.ReactNode | React.ReactNode[]) {
return render(<AblyProvider client={client as unknown as Ably.AbstractRealtime}>{children}</AblyProvider>);
return render(<AblyProvider client={client as unknown as Ably.RealtimeInterface}>{children}</AblyProvider>);
}

describe('useChannel', () => {
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('useChannel', () => {
it('useChannel works with multiple clients', async () => {
renderInCtxProvider(
ablyClient,
<AblyProvider client={otherClient as unknown as Ably.AbstractRealtime} id="otherClient">
<AblyProvider client={otherClient as unknown as Ably.RealtimeInterface} id="otherClient">
<UseChannelComponentMultipleClients />
</AblyProvider>
);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/react-hooks/src/hooks/useChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type AblyMessageCallback = Ably.messageCallback<Ably.Message>;

export interface ChannelResult {
channel: Ably.RealtimeChannel;
ably: Ably.AbstractRealtime;
ably: Ably.RealtimeInterface;
connectionError: Ably.ErrorInfo | null;
channelError: Ably.ErrorInfo | null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { act } from 'react-dom/test-utils';
import { AblyProvider } from '../AblyProvider.js';

function renderInCtxProvider(client: FakeAblySdk, children: React.ReactNode | React.ReactNode[]) {
return render(<AblyProvider client={client as unknown as Ably.AbstractRealtime}>{children}</AblyProvider>);
return render(<AblyProvider client={client as unknown as Ably.RealtimeInterface}>{children}</AblyProvider>);
}

describe('useChannelStateListener', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AblyProvider } from '../AblyProvider.js';
import { useConnectionStateListener } from './useConnectionStateListener.js';

function renderInCtxProvider(client: FakeAblySdk, children: React.ReactNode | React.ReactNode[]) {
return render(<AblyProvider client={client as unknown as Ably.AbstractRealtime}>{children}</AblyProvider>);
return render(<AblyProvider client={client as unknown as Ably.RealtimeInterface}>{children}</AblyProvider>);
}

describe('useConnectionStateListener', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/platform/react-hooks/src/hooks/usePresence.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AblyProvider } from '../AblyProvider.js';
import * as Ably from '../../../../../ably.js';

function renderInCtxProvider(client: FakeAblySdk, children: React.ReactNode | React.ReactNode[]) {
return render(<AblyProvider client={client as unknown as Ably.AbstractRealtime}>{children}</AblyProvider>);
return render(<AblyProvider client={client as unknown as Ably.RealtimeInterface}>{children}</AblyProvider>);
}

const testChannelName = 'testChannel';
Expand Down Expand Up @@ -97,7 +97,7 @@ describe('usePresence', () => {
it('usePresence works with multiple clients', async () => {
renderInCtxProvider(
ablyClient,
<AblyProvider id="otherClient" client={otherClient as unknown as Ably.AbstractRealtime}>
<AblyProvider id="otherClient" client={otherClient as unknown as Ably.RealtimeInterface}>
<UsePresenceComponentMultipleClients />
</AblyProvider>
);
Expand Down
10 changes: 5 additions & 5 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1340,8 +1340,8 @@ export interface PushChannelsParams {
/**
* The `StatsParams` interface describes the parameters accepted by the following methods:
*
* - {@link AbstractRest.stats}
* - {@link AbstractRealtime.stats}
* - {@link RestInterface.stats}
* - {@link RealtimeInterface.stats}
*/
export interface StatsParams {
/**
Expand Down Expand Up @@ -1662,7 +1662,7 @@ export interface EventEmitter<CallbackType, ResultType, EventType> {
/**
* A client that offers a simple stateless API to interact directly with Ably's REST API.
*/
export interface AbstractRest {
export interface RestInterface {
/**
* An {@link Auth} object.
*/
Expand Down Expand Up @@ -1734,9 +1734,9 @@ export interface AbstractRest {
}

/**
* A client that extends the functionality of {@link AbstractRest} and provides additional realtime-specific features.
* A client that extends the functionality of {@link RestInterface} and provides additional realtime-specific features.
*/
export interface AbstractRealtime {
export interface RealtimeInterface {
/**
* A client ID, used for identifying this client when publishing messages or for presence purposes. The `clientId` can be any non-empty string, except it cannot contain a `*`. This option is primarily intended to be used in situations where the library is instantiated with a key. A `clientId` may also be implicit in a token used to instantiate the library; an error will be raised if a `clientId` specified here conflicts with the `clientId` implicit in the token.
*/
Expand Down

0 comments on commit 2d0aa6a

Please sign in to comment.