Disable usePresence flags by default (#226)

This commit is contained in:
Cole Lawrence 2022-06-16 07:59:09 -04:00 committed by GitHub
parent e8c8168f0b
commit 4e4b8f83e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,7 +21,9 @@ export enum PresenceFlag {
const undefinedD = prism(() => undefined) const undefinedD = prism(() => undefined)
undefinedD.keepHot() // constant anyway... undefinedD.keepHot() // constant anyway...
function createPresenceContext(): InternalPresenceContext { function createPresenceContext(options: {
enabled: boolean
}): InternalPresenceContext {
const currentUserHoverItemB = new Box<StudioSheetItemKey | undefined>( const currentUserHoverItemB = new Box<StudioSheetItemKey | undefined>(
undefined, undefined,
) )
@ -61,6 +63,8 @@ function createPresenceContext(): InternalPresenceContext {
} }
}, },
usePresenceFlag(itemKey) { usePresenceFlag(itemKey) {
if (!options.enabled) return undefined
const focusD = useMemo(() => { const focusD = useMemo(() => {
if (!itemKey) return undefinedD if (!itemKey) return undefinedD
// this is the thing being hovered // this is the thing being hovered
@ -127,10 +131,10 @@ type InternalPresenceContext = {
} }
const presenceInternalCtx = React.createContext<InternalPresenceContext>( const presenceInternalCtx = React.createContext<InternalPresenceContext>(
createPresenceContext(), createPresenceContext({enabled: false}),
) )
export function ProvidePresenceRoot({children}: React.PropsWithChildren<{}>) { export function ProvidePresenceRoot({children}: React.PropsWithChildren<{}>) {
const presence = useMemo(() => createPresenceContext(), []) const presence = useMemo(() => createPresenceContext({enabled: false}), [])
return React.createElement( return React.createElement(
presenceInternalCtx.Provider, presenceInternalCtx.Provider,
{children, value: presence}, {children, value: presence},