perf: getEnvironment() -> env (#2636)

This commit is contained in:
Simon He
2023-06-01 11:23:38 +08:00
committed by GitHub
parent e1314730be
commit fc9462eee9
16 changed files with 70 additions and 86 deletions

View File

@@ -1,4 +1,4 @@
import { getEnvironment } from '@affine/env/config';
import { env } from '@affine/env/config';
import { atomWithObservable, atomWithStorage } from 'jotai/utils';
import { Observable } from 'rxjs';
@@ -21,9 +21,8 @@ function rpcToObservable<
) {
return new Observable<T>(subscriber => {
subscriber.next(initialValue);
const environment = getEnvironment();
onSubscribe?.();
if (typeof window === 'undefined' || !environment.isDesktop || !event) {
if (typeof window === 'undefined' || !env.isDesktop || !event) {
subscriber.complete();
return () => {};
}

View File

@@ -1,4 +1,4 @@
import { getEnvironment } from '@affine/env';
import { env } from '@affine/env';
import { Skeleton } from '@mui/material';
import { assignInlineVars } from '@vanilla-extract/dynamic';
import { useAtom, useAtomValue } from 'jotai';
@@ -79,8 +79,7 @@ export function AppSidebar(props: AppSidebarProps): ReactElement {
// disable animation to avoid UI flash
const enableAnimation = useEnableAnimation();
const environment = getEnvironment();
const isMacosDesktop = environment.isDesktop && environment.isMacOs;
const isMacosDesktop = env.isDesktop && env.isMacOs;
if (initialRender) {
// avoid the UI flash
return <div />;

View File

@@ -1,4 +1,4 @@
import { getEnvironment } from '@affine/env/config';
import { env } from '@affine/env/config';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { SearchIcon } from '@blocksuite/icons';
import clsx from 'clsx';
@@ -13,8 +13,7 @@ interface QuickSearchInputProps extends React.HTMLAttributes<HTMLDivElement> {
// Although it is called an input, it is actually a button.
export function QuickSearchInput({ onClick, ...props }: QuickSearchInputProps) {
const t = useAFFiNEI18N();
const environment = getEnvironment();
const isMac = environment.isBrowser && environment.isMacOs;
const isMac = env.isBrowser && env.isMacOs;
return (
<div

View File

@@ -1,4 +1,4 @@
import { getEnvironment } from '@affine/env/config';
import { env } from '@affine/env/config';
import { ArrowLeftSmallIcon, ArrowRightSmallIcon } from '@blocksuite/icons';
import { useAtomValue } from 'jotai';
@@ -18,12 +18,11 @@ export type SidebarHeaderProps = {
export const SidebarHeader = (props: SidebarHeaderProps) => {
const open = useAtomValue(appSidebarOpenAtom);
const environment = getEnvironment();
return (
<div className={navHeaderStyle} data-open={open}>
{environment.isDesktop && (
{env.isDesktop && (
<>
{environment.isMacOs && <div style={{ flex: 1 }} />}
{env.isMacOs && <div style={{ flex: 1 }} />}
<IconButton
size="middle"
data-testid="app-sidebar-arrow-button-back"
@@ -51,7 +50,7 @@ export const SidebarHeader = (props: SidebarHeaderProps) => {
<ArrowRightSmallIcon />
</IconButton>
{!environment.isMacOs && <div style={{ flex: 1 }} />}
{!env.isMacOs && <div style={{ flex: 1 }} />}
</>
)}
{open && <SidebarSwitch />}