Skip to content

Commit dd4c8c5

Browse files
committed
Rename to StoreDebugAPI, remove React context, use Registry WeakMap
1 parent 052e7e9 commit dd4c8c5

File tree

16 files changed

+73
-135
lines changed

16 files changed

+73
-135
lines changed

packages/api/src/boot/hook.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export {
4747
useRenderAttachment,
4848
useRenderToast,
4949
useRenderTypingIndicator,
50-
useRootDebugAPI,
5150
useSendBoxAttachments,
5251
useSendBoxValue,
5352
useSendEvent,

packages/api/src/hooks/Composer.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ import ActivityListenerComposer from '../providers/ActivityListener/ActivityList
6060
import ActivitySendStatusComposer from '../providers/ActivitySendStatus/ActivitySendStatusComposer';
6161
import ActivitySendStatusTelemetryComposer from '../providers/ActivitySendStatusTelemetry/ActivitySendStatusTelemetryComposer';
6262
import ActivityTypingComposer from '../providers/ActivityTyping/ActivityTypingComposer';
63-
import DebugAPIComposer from '../providers/DebugAPI/DebugAPIComposer';
6463
import GroupActivitiesComposer from '../providers/GroupActivities/GroupActivitiesComposer';
6564
import PonyfillComposer from '../providers/Ponyfill/PonyfillComposer';
6665
import StyleOptionsComposer from '../providers/StyleOptions/StyleOptionsComposer';
@@ -748,19 +747,17 @@ const ComposerWithStore = ({ onTelemetry, store, ...props }: ComposerWithStorePr
748747
}, [ponyfill, store]);
749748

750749
return (
751-
<DebugAPIComposer rootDebugAPI={memoizedStore['debugAPI']}>
752-
<Provider context={WebChatReduxContext} store={memoizedStore}>
753-
<ReduxStoreComposer store={memoizedStore}>
754-
<GraphProvider store={memoizedStore}>
755-
<ActivityKeyerComposer>
756-
<ActivityAcknowledgementComposer>
757-
<ComposerCore onTelemetry={onTelemetry} {...props} />
758-
</ActivityAcknowledgementComposer>
759-
</ActivityKeyerComposer>
760-
</GraphProvider>
761-
</ReduxStoreComposer>
762-
</Provider>
763-
</DebugAPIComposer>
750+
<Provider context={WebChatReduxContext} store={memoizedStore}>
751+
<ReduxStoreComposer store={memoizedStore}>
752+
<GraphProvider store={memoizedStore}>
753+
<ActivityKeyerComposer>
754+
<ActivityAcknowledgementComposer>
755+
<ComposerCore onTelemetry={onTelemetry} {...props} />
756+
</ActivityAcknowledgementComposer>
757+
</ActivityKeyerComposer>
758+
</GraphProvider>
759+
</ReduxStoreComposer>
760+
</Provider>
764761
);
765762
};
766763

packages/api/src/hooks/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ import useVoiceSelector from './useVoiceSelector';
7474

7575
export { useBuildRenderActivityCallback } from '@msinternal/botframework-webchat-api-middleware';
7676
export { useSuggestedActionsHooks } from '@msinternal/botframework-webchat-redux-store';
77-
export { default as useRootDebugAPI } from '../providers/DebugAPI/useRootDebugAPI';
7877

7978
export {
8079
useActiveTyping,

packages/api/src/providers/DebugAPI/DebugAPIComposer.tsx

Lines changed: 0 additions & 34 deletions
This file was deleted.

packages/api/src/providers/DebugAPI/private/DebugAPIContext.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

packages/api/src/providers/DebugAPI/useRootDebugAPI.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/component/src/ActivityDebug/RestrictedActivityDebugAPI.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import type { ArrayElement } from 'type-fest';
44
const BREAKPOINT_NAMES = ['render'] as const;
55

66
type ActivityBreakpointName = ArrayElement<typeof BREAKPOINT_NAMES>;
7-
type ActivityDebugContext = { readonly activity: any;
8-
};
7+
type ActivityDebugContext = { readonly activity: any };
98

109
class RestrictedActivityDebugAPI extends RestrictedDebugAPI<ActivityBreakpointName, ActivityDebugContext> {
1110
constructor(getActivity: () => any) {

packages/component/src/Composer.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable react/require-default-props */
2+
13
import {
24
Composer as APIComposer,
35
extractSendBoxMiddleware,
@@ -9,7 +11,6 @@ import {
911
type SendBoxToolbarMiddleware
1012
} from 'botframework-webchat-api';
1113
import { DecoratorComposer, type DecoratorMiddleware } from 'botframework-webchat-api/decorator';
12-
import { useRootDebugAPI } from 'botframework-webchat-api/hook';
1314
import { type Polymiddleware } from 'botframework-webchat-api/middleware';
1415
import { singleToArray } from 'botframework-webchat-core';
1516
import classNames from 'classnames';
@@ -18,6 +19,7 @@ import PropTypes from 'prop-types';
1819
import React, { memo, useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
1920
import { Composer as SayComposer } from 'react-say';
2021

22+
import { StoreDebugAPIRegistry, type StoreDebugAPI } from 'botframework-webchat-core/internal';
2123
import createDefaultAttachmentMiddleware from './Attachment/createMiddleware';
2224
import BuiltInDecorator from './BuiltInDecorator';
2325
import Dictation from './Dictation';
@@ -65,9 +67,9 @@ function styleSetToEmotionObjects(styleToEmotionObject, styleSet) {
6567
}
6668

6769
type ComposerCoreUIProps = {
68-
// eslint-disable-next-line react/require-default-props
6970
readonly children?: ReactNode | undefined;
7071
readonly nonce: string | undefined;
72+
readonly storeDebugAPI?: StoreDebugAPI | undefined;
7173
};
7274

7375
const ROOT_STYLE = {
@@ -84,9 +86,8 @@ const ROOT_STYLE = {
8486
}
8587
};
8688

87-
const ComposerCoreUI = memo(({ children, nonce }: ComposerCoreUIProps) => {
89+
const ComposerCoreUI = memo(({ children, nonce, storeDebugAPI }: ComposerCoreUIProps) => {
8890
const [{ internalLiveRegionFadeAfter }] = useStyleOptions();
89-
const [rootDebugAPI] = useRootDebugAPI();
9091
const rootClassName = useStyleToEmotionObject()(ROOT_STYLE) + '';
9192
const rootRef = useRef<HTMLDivElement>(null);
9293
const trackException = useTrackException();
@@ -110,15 +111,15 @@ const ComposerCoreUI = memo(({ children, nonce }: ComposerCoreUIProps) => {
110111
const { current } = rootRef;
111112

112113
if (current) {
113-
current['webChat'] = rootDebugAPI;
114+
current['webChat'] = storeDebugAPI;
114115

115116
return () => delete current['webChat'];
116117
}
117118

118119
return () => {
119120
// Intentionally left blank.
120121
};
121-
}, [rootDebugAPI]);
122+
}, [storeDebugAPI]);
122123

123124
return (
124125
<CSSCustomPropertiesContainer
@@ -158,6 +159,7 @@ type ComposerCoreProps = Readonly<{
158159
newLineOptions: { markdownRespectCRLF: boolean },
159160
linkOptions: { externalLinkAlt: string }
160161
) => string;
162+
storeDebugAPI?: StoreDebugAPI | undefined;
161163
styleSet?: any;
162164
suggestedActionsAccessKey?: boolean | string;
163165
webSpeechPonyfillFactory?: WebSpeechPonyfillFactory;
@@ -168,6 +170,7 @@ const ComposerCore = ({
168170
extraStyleSet,
169171
nonce,
170172
renderMarkdown,
173+
storeDebugAPI,
171174
styleSet,
172175
suggestedActionsAccessKey,
173176
webSpeechPonyfillFactory
@@ -309,7 +312,9 @@ const ComposerCore = ({
309312
return (
310313
<SayComposer ponyfill={webSpeechPonyfill}>
311314
<WebChatUIContext.Provider value={context}>
312-
<ComposerCoreUI nonce={nonce}>{children}</ComposerCoreUI>
315+
<ComposerCoreUI nonce={nonce} storeDebugAPI={storeDebugAPI}>
316+
{children}
317+
</ComposerCoreUI>
313318
</WebChatUIContext.Provider>
314319
</SayComposer>
315320
);
@@ -458,6 +463,8 @@ const Composer = ({
458463
[sendBoxToolbarMiddlewareFromProps, theme.sendBoxToolbarMiddleware]
459464
);
460465

466+
const storeDebugAPI = useMemo(() => StoreDebugAPIRegistry.get(composerProps.store), [composerProps.store]);
467+
461468
return (
462469
<APIComposer
463470
activityMiddleware={patchedActivityMiddleware}
@@ -487,6 +494,7 @@ const Composer = ({
487494
extraStyleSet={extraStyleSet}
488495
nonce={nonce}
489496
renderMarkdown={renderMarkdown}
497+
storeDebugAPI={storeDebugAPI}
490498
styleSet={styleSet}
491499
suggestedActionsAccessKey={suggestedActionsAccessKey}
492500
webSpeechPonyfillFactory={webSpeechPonyfillFactory}

packages/core/src/createReducer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ import suggestedActions from './reducers/suggestedActions';
1919
import suggestedActionsOriginActivity from './reducers/suggestedActionsOriginActivity';
2020

2121
import type { GlobalScopePonyfill } from './types/GlobalScopePonyfill';
22-
import type { RestrictedRootDebugAPI } from './types/RootDebugAPI';
22+
import type { RestrictedStoreDebugAPI } from './types/StoreDebugAPI';
2323

24-
export default function createReducer(ponyfill: GlobalScopePonyfill, restrictedRootDebugAPI: RestrictedRootDebugAPI) {
24+
export default function createReducer(ponyfill: GlobalScopePonyfill, restrictedStoreDebugAPI: RestrictedStoreDebugAPI) {
2525
return combineActivitiesReducer(
2626
ponyfill,
27-
restrictedRootDebugAPI,
27+
restrictedStoreDebugAPI,
2828
combineReducers({
2929
connectivityStatus,
3030
dictateInterims,

packages/core/src/createStore.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import createSagaMiddleware from 'redux-saga';
55
import sagaError from './actions/sagaError';
66
import createReducer from './createReducer';
77
import createSagas from './createSagas';
8-
import { RestrictedRootDebugAPI } from './types/RootDebugAPI';
8+
import { RestrictedStoreDebugAPI } from './types/StoreDebugAPI';
99

1010
import type { GlobalScopePonyfill } from './types/GlobalScopePonyfill';
11+
import { StoreDebugAPIRegistry } from './internal';
1112

1213
type CreateStoreOptions = {
1314
/**
@@ -113,24 +114,24 @@ export function withOptions(options: CreateStoreOptions, initialState?, ...middl
113114
// eslint-disable-next-line prefer-const
114115
let store: Store | undefined;
115116

116-
const restrictedRootDebugAPI = new RestrictedRootDebugAPI(() => store?.getState().activities);
117+
const restrictedStoreDebugAPI = new RestrictedStoreDebugAPI(() => store?.getState().activities);
117118

118119
// We are sure the "getStore" (first argument) is not called on "createEnhancerAndSagaMiddleware()".
119120
const { enhancer, sagaMiddleware } = createEnhancerAndSagaMiddleware(() => store, ...middlewares);
120121

121122
store = createReduxStore(
122-
createReducer(ponyfill, restrictedRootDebugAPI),
123+
createReducer(ponyfill, restrictedStoreDebugAPI),
123124
initialState || {},
124125
options.devTools ? composeWithDevTools(enhancer) : enhancer
125126
);
126127

127128
// TODO: [P1] When we redesign the store and chat adapter, we should have the Debug API stored somewhere else.
128-
store['debugAPI'] = restrictedRootDebugAPI.toPublic();
129+
StoreDebugAPIRegistry.set(store, restrictedStoreDebugAPI.toPublic());
129130

130131
// TODO: [P1] When we redesign the store and chat adapter, we shoulstore.getState().activities
131132
sagaMiddleware.run(createSagas({ ponyfill }));
132133

133-
return Object.freeze(store);
134+
return store;
134135
}
135136

136137
/**

0 commit comments

Comments
 (0)