Skip to content

Commit

Permalink
Merge pull request #1509 from ably/fix-react-hooks-ably-import
Browse files Browse the repository at this point in the history
fix: use 'ably' as import path from react-hooks
  • Loading branch information
owenpearson authored Nov 20, 2023
2 parents 3dbd400 + 7af5a4b commit c3c09dd
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 14 deletions.
8 changes: 3 additions & 5 deletions src/platform/react-hooks/src/AblyProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import * as Ably from 'ably';
import { Types } from '../../../../ably.js';
import { Types } from 'ably';
import React, { useMemo } from 'react';

const canUseSymbol = typeof Symbol === 'function' && typeof Symbol.for === 'function';
Expand Down Expand Up @@ -31,15 +29,15 @@ export const AblyProvider = ({ client, children, id = 'default' }: AblyProviderP
throw new Error('AblyProvider: the `client` prop is required');
}

if (!(client instanceof Ably.Realtime) && !client?.options?.promises) {
if (!(client instanceof Ably.Realtime) && !(client as any)?.options?.promises) {
throw new Error('AblyProvider: the `client` prop must take an instance of Ably.Realtime.Promise');
}

const realtime = useMemo(() => client, [client]);

let context = getContext(id);
if (!context) {
context = ctxMap[id] = React.createContext(realtime ?? 1);
context = ctxMap[id] = React.createContext(realtime);
}

return <context.Provider value={realtime}>{children}</context.Provider>;
Expand Down
2 changes: 1 addition & 1 deletion 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 } from 'ably';

export type ChannelNameAndOptions = {
channelName: string;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/react-hooks/src/hooks/useAbly.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { getContext } from '../AblyProvider.js';
import * as API from '../../../../../callbacks.js';
import * as API from 'ably';

export function useAbly(id = 'default'): API.Types.RealtimePromise {
const client = React.useContext(getContext(id)) as API.Types.RealtimePromise;
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
@@ -1,4 +1,4 @@
import { Types } from '../../../../../ably.js';
import { Types } from 'ably';
import { useEffect, useMemo, useRef } from 'react';
import { channelOptionsWithAgent, ChannelParameters } from '../AblyReactHooks.js';
import { useAbly } from './useAbly.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useRef } from 'react';
import { Types } from '../../../../../ably.js';
import { Types } from 'ably';
import { ChannelNameAndId, ChannelNameAndOptions, channelOptionsWithAgent } from '../AblyReactHooks.js';
import { useAbly } from './useAbly.js';
import { useEventListener } from './useEventListener.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Types } from '../../../../../ably.js';
import { Types } from 'ably';
import { useAbly } from './useAbly.js';
import { useEventListener } from './useEventListener.js';

Expand Down
2 changes: 1 addition & 1 deletion src/platform/react-hooks/src/hooks/useEventListener.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Types } from '../../../../../ably.js';
import { Types } from 'ably';
import { useEffect, useRef } from 'react';

type EventListener<T> = (stateChange: T) => any;
Expand Down
2 changes: 1 addition & 1 deletion 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 } from 'ably';
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { channelOptionsWithAgent, ChannelParameters } from '../AblyReactHooks.js';
import { useAbly } from './useAbly.js';
Expand Down
2 changes: 1 addition & 1 deletion src/platform/react-hooks/src/hooks/useStateErrors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Types } from '../../../../../ably.js';
import { Types } from 'ably';
import { useState } from 'react';
import { useConnectionStateListener } from './useConnectionStateListener.js';
import { useChannelStateListener } from './useChannelStateListener.js';
Expand Down
5 changes: 4 additions & 1 deletion src/platform/react-hooks/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"allowJs": true,
"jsx": "react-jsx",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"types": ["vitest/globals"]
"types": ["vitest/globals"],
"paths": {
"ably": ["../../../"]
}
}
}

0 comments on commit c3c09dd

Please sign in to comment.