main
js 35 lines 957 Bytes
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10 import type {CurrentDispatcherRef, LegacyDispatcherRef} from '../types';
11
12 export function getDispatcherRef(renderer: {
13 +currentDispatcherRef?: LegacyDispatcherRef | CurrentDispatcherRef,
14 ...
15 }): void | CurrentDispatcherRef {
16 if (renderer.currentDispatcherRef === undefined) {
17 return undefined;
18 }
19 const injectedRef = renderer.currentDispatcherRef;
20 if (
21 typeof injectedRef.H === 'undefined' &&
22 typeof injectedRef.current !== 'undefined'
23 ) {
24 // We got a legacy dispatcher injected, let's create a wrapper proxy to translate.
25 return {
26 get H() {
27 return (injectedRef as any).current;
28 },
29 set H(value) {
30 (injectedRef as any).current = value;
31 },
32 };
33 }
34 return injectedRef as any;
35 }