Skip to content

Commit

Permalink
Merge branch 'fix/tolerant-providers' of github.com:executablebooks/t…
Browse files Browse the repository at this point in the history
…hebe into fix/tolerant-providers
  • Loading branch information
stevejpurves committed Sep 4, 2023
2 parents c4e9c6f + bf91f51 commit c0f3b2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
15 changes: 9 additions & 6 deletions packages/react/src/ThebeServerProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ type ListenerFn = (data: ThebeEventData) => void;

export const ThebeServerContext = React.createContext<
| {
connecting: boolean;
ready: boolean;
config?: Config;
events?: ThebeEvents;
server?: ThebeServer;
connecting: boolean;
ready: boolean;
connect: () => void;
disconnect: () => Promise<void>;
connect?: () => void;
disconnect?: () => Promise<void>;
}
| undefined
>(undefined);
Expand Down Expand Up @@ -147,7 +147,10 @@ export function useThebeServer() {
const { core } = thebe ?? {};

const serverContext = useContext(ThebeServerContext);
const { config, events, server, connecting, ready, connect, disconnect } = serverContext ?? {};
const { config, events, server, connecting, ready, connect, disconnect } = serverContext ?? {
ready: false,
connecting: false,
};

const [error, setError] = useState<string | undefined>(); // TODO how to handle errors better via the provider
const [eventCallbacks, setEventCallbacks] = useState<ThebeEventCb[]>([]);
Expand Down Expand Up @@ -195,5 +198,5 @@ export function useThebeServer() {
subscribe,
unsubAll,
}
: {};
: { connecting: false, ready: false };
}
6 changes: 3 additions & 3 deletions packages/react/src/ThebeSessionProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ interface ThebeSessionContextData {
path?: string;
session?: ThebeSession;
error?: string;
starting?: boolean;
ready?: boolean;
starting: boolean;
ready: boolean;
start?: () => Promise<void>;
shutdown?: () => Promise<void>;
}
Expand Down Expand Up @@ -104,5 +104,5 @@ export function ThebeSessionProvider({

export function useThebeSession(): ThebeSessionContextData {
const sessionContext = useContext(ThebeSessionContext);
return sessionContext ?? {};
return sessionContext ?? { starting: false, ready: false };
}

0 comments on commit c0f3b2a

Please sign in to comment.