Skip to content

Commit f07832d

Browse files
committed
Align to state hooks pattern
1 parent 749aa19 commit f07832d

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

packages/fluent-theme/src/components/assets/AssetComposer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ const AssetComposer = memo(({ children }: AssetComposerProps) => {
2222
useEffect(() => () => URL.revokeObjectURL(slidingDotsURL), [slidingDotsURL]);
2323

2424
const context = useMemo<ContextType>(
25-
() => Object.freeze({ urlMap: new Map<AssetName, URL>([['sliding dots', new URL(slidingDotsURL)]]) }),
25+
() =>
26+
Object.freeze({
27+
urlStateMap: new Map<AssetName, readonly [URL]>([['sliding dots', Object.freeze([new URL(slidingDotsURL)])]])
28+
}),
2629
[slidingDotsURL]
2730
);
2831

packages/fluent-theme/src/components/assets/SlidingDots.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ type SlidingDotsProps = Readonly<{ className: string }>;
99

1010
const SlidingDots = ({ className }: SlidingDotsProps) => {
1111
const [shouldReduceMotion] = useShouldReduceMotion();
12+
const [url] = useAssetURL('sliding dots');
1213
const localize = useLocalizer();
1314
const objectElementRef = useRef<HTMLObjectElement>(null);
14-
const url = useAssetURL('sliding dots');
1515

1616
const altText = localize('TYPING_INDICATOR_ALT');
1717
const shouldReduceMotionRef = useRefFrom(shouldReduceMotion);

packages/fluent-theme/src/components/assets/private/Context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { createContext } from 'react';
33
import type { AssetName } from '../AssetName';
44

55
type ContextType = Readonly<{
6-
urlMap: ReadonlyMap<AssetName, URL>;
6+
urlStateMap: ReadonlyMap<AssetName, readonly [URL]>;
77
}>;
88

99
type ContextAsGetter<T extends Record<string, unknown>> =
1010
T extends Record<infer K, infer V> ? Record<K, { get(): V }> : never;
1111

1212
const defaultContextValue: ContextAsGetter<ContextType> = {
13-
urlMap: {
13+
urlStateMap: {
1414
get() {
1515
throw new Error('urlMap cannot be used outside of <AssetComposerContext>.');
1616
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { type AssetName } from './AssetName';
22
import useContext from './private/useContext';
33

4-
export default function useAssetURL(assetName: AssetName): URL {
5-
const url = useContext().urlMap.get(assetName);
4+
export default function useAssetURL(assetName: AssetName): readonly [URL] {
5+
const urlState = useContext().urlStateMap.get(assetName);
66

7-
if (!url) {
7+
if (!urlState) {
88
throw new Error(`botframework-webchat-fluent-theme internal: Asset "${assetName}" was not found.`);
99
}
1010

11-
return url;
11+
return urlState;
1212
}

0 commit comments

Comments
 (0)