Skip to content

Commit

Permalink
Remove Types.ErrorInfo
Browse files Browse the repository at this point in the history
To avoid a clash with the top-level class of the same name when we
remove the Types namespace in #909.
  • Loading branch information
lawrence-forooghian committed Nov 30, 2023
1 parent 0596cd4 commit 1d0c7e9
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 70 deletions.
91 changes: 43 additions & 48 deletions ably.d.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/common/lib/types/errorinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export interface IConvertibleToErrorInfo {
statusCode: number;
}

export default class ErrorInfo extends Error implements IPartialErrorInfo, API.Types.ErrorInfo {
export default class ErrorInfo extends Error implements IPartialErrorInfo, API.ErrorInfo {
code: number;
statusCode: number;
cause?: string | Error | ErrorInfo;
Expand Down
6 changes: 3 additions & 3 deletions src/platform/react-hooks/sample-app/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Types } from 'ably';
import { Types, ErrorInfo } from 'ably';
import React, { useState } from 'react';
import {
useChannel,
Expand Down Expand Up @@ -33,7 +33,7 @@ function App() {
const [ablyErr, setAblyErr] = useState('');
const [channelState, setChannelState] = useState(channel.state);
const [previousChannelState, setPreviousChannelState] = useState<undefined | Types.ChannelState>();
const [channelStateReason, setChannelStateReason] = useState<undefined | Types.ErrorInfo>();
const [channelStateReason, setChannelStateReason] = useState<undefined | ErrorInfo>();

useChannelStateListener('your-channel-name', (stateChange) => {
setAblyErr(JSON.stringify(stateChange.reason));
Expand Down Expand Up @@ -106,7 +106,7 @@ function App() {
function ConnectionState() {
const ably = useAbly();
const [connectionState, setConnectionState] = useState(ably.connection.state);
const [connectionError, setConnectionError] = useState<Types.ErrorInfo | null>(null);
const [connectionError, setConnectionError] = useState<ErrorInfo | null>(null);
useConnectionStateListener((stateChange) => {
console.log(stateChange);
setConnectionState(stateChange.current);
Expand Down
6 changes: 3 additions & 3 deletions src/platform/react-hooks/src/AblyReactHooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Types } from '../../../../ably.js';
import { Types, ErrorInfo } from '../../../../ably.js';

export type ChannelNameAndOptions = {
channelName: string;
Expand All @@ -7,8 +7,8 @@ export type ChannelNameAndOptions = {
subscribeOnly?: boolean;
skip?: boolean;

onConnectionError?: (error: Types.ErrorInfo) => unknown;
onChannelError?: (error: Types.ErrorInfo) => unknown;
onConnectionError?: (error: ErrorInfo) => unknown;
onChannelError?: (error: ErrorInfo) => unknown;
};

export type ChannelNameAndId = {
Expand Down
6 changes: 3 additions & 3 deletions src/platform/react-hooks/src/hooks/useChannel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { it, beforeEach, describe, expect, vi } from 'vitest';
import { useChannel } from './useChannel.js';
import { render, screen, waitFor } from '@testing-library/react';
import { FakeAblySdk, FakeAblyChannels } from '../fakes/ably.js';
import { Types } from '../../../../../ably.js';
import { Types, ErrorInfo } from '../../../../../ably.js';
import { act } from 'react-dom/test-utils';
import { AblyProvider } from '../AblyProvider.js';

Expand Down Expand Up @@ -202,8 +202,8 @@ const UseChannelComponent = ({ skip }: { skip?: boolean }) => {
};

interface UseChannelStateErrorsComponentProps {
onConnectionError?: (err: Types.ErrorInfo) => unknown;
onChannelError?: (err: Types.ErrorInfo) => unknown;
onConnectionError?: (err: ErrorInfo) => unknown;
onChannelError?: (err: ErrorInfo) => unknown;
}

const UseChannelStateErrorsComponent = ({ onConnectionError, onChannelError }: UseChannelStateErrorsComponentProps) => {
Expand Down
6 changes: 3 additions & 3 deletions src/platform/react-hooks/src/hooks/useChannel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Types } from '../../../../../ably.js';
import { Types, ErrorInfo } from '../../../../../ably.js';
import { useEffect, useMemo, useRef } from 'react';
import { channelOptionsWithAgent, ChannelParameters } from '../AblyReactHooks.js';
import { useAbly } from './useAbly.js';
Expand All @@ -9,8 +9,8 @@ export type AblyMessageCallback = Types.messageCallback<Types.Message>;
export interface ChannelResult {
channel: Types.RealtimeChannel;
ably: Types.Realtime;
connectionError: Types.ErrorInfo | null;
channelError: Types.ErrorInfo | null;
connectionError: ErrorInfo | null;
channelError: ErrorInfo | null;
}

type SubscribeArgs = [string, AblyMessageCallback] | [AblyMessageCallback];
Expand Down
6 changes: 3 additions & 3 deletions src/platform/react-hooks/src/hooks/usePresence.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { usePresence } from './usePresence.js';
import { render, screen, act } from '@testing-library/react';
import { FakeAblySdk, FakeAblyChannels } from '../fakes/ably.js';
import { AblyProvider } from '../AblyProvider.js';
import { Types } from '../../../../../ably.js';
import { Types, ErrorInfo } from '../../../../../ably.js';

function renderInCtxProvider(client: FakeAblySdk, children: React.ReactNode | React.ReactNode[]) {
return render(<AblyProvider client={client as unknown as Types.Realtime}>{children}</AblyProvider>);
Expand Down Expand Up @@ -215,8 +215,8 @@ const UsePresenceComponentMultipleClients = () => {
};

interface UsePresenceStateErrorsComponentProps {
onConnectionError?: (err: Types.ErrorInfo) => unknown;
onChannelError?: (err: Types.ErrorInfo) => unknown;
onConnectionError?: (err: ErrorInfo) => unknown;
onChannelError?: (err: ErrorInfo) => unknown;
}

const UsePresenceStateErrorsComponent = ({
Expand Down
6 changes: 3 additions & 3 deletions src/platform/react-hooks/src/hooks/usePresence.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Types } from '../../../../../ably.js';
import { Types, ErrorInfo } from '../../../../../ably.js';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { channelOptionsWithAgent, ChannelParameters } from '../AblyReactHooks.js';
import { useAbly } from './useAbly.js';
Expand All @@ -7,8 +7,8 @@ import { useStateErrors } from './useStateErrors.js';
export interface PresenceResult<T> {
presenceData: PresenceMessage<T>[];
updateStatus: (messageOrPresenceObject: T) => void;
connectionError: Types.ErrorInfo | null;
channelError: Types.ErrorInfo | null;
connectionError: ErrorInfo | null;
channelError: ErrorInfo | null;
}

export type OnPresenceMessageReceived<T> = (presenceData: PresenceMessage<T>) => void;
Expand Down
6 changes: 3 additions & 3 deletions src/platform/react-hooks/src/hooks/useStateErrors.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Types } from '../../../../../ably.js';
import { ErrorInfo } from '../../../../../ably.js';
import { useState } from 'react';
import { useConnectionStateListener } from './useConnectionStateListener.js';
import { useChannelStateListener } from './useChannelStateListener.js';
import { ChannelNameAndOptions } from '../AblyReactHooks.js';

export function useStateErrors(params: ChannelNameAndOptions) {
const [connectionError, setConnectionError] = useState<Types.ErrorInfo | null>(null);
const [channelError, setChannelError] = useState<Types.ErrorInfo | null>(null);
const [connectionError, setConnectionError] = useState<ErrorInfo | null>(null);
const [channelError, setChannelError] = useState<ErrorInfo | null>(null);

useConnectionStateListener(
['suspended', 'failed', 'disconnected'],
Expand Down

0 comments on commit 1d0c7e9

Please sign in to comment.