Skip to content

refactor: solve circule dependency #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import classNames from 'classnames';
import ResizeObserver from 'rc-resize-observer';
import type { ComponentType } from './Overflow';
import type { ComponentType } from './RawItem';

// Use shared variable to save bundle size
const UNDEFINED = undefined;
Expand Down
27 changes: 5 additions & 22 deletions src/Overflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,16 @@ import ResizeObserver from 'rc-resize-observer';
import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect';
import Item from './Item';
import useEffectState, { useBatcher } from './hooks/useEffectState';
import type { ComponentType } from './RawItem';
import RawItem from './RawItem';

export const OverflowContext = React.createContext<{
prefixCls: string;
responsive: boolean;
order: number;
registerSize: (key: React.Key, width: number | null) => void;
display: boolean;

invalidate: boolean;

// Item Usage
item?: any;
itemKey?: React.Key;

// Rest Usage
className?: string;
}>(null);
import { OverflowContext } from './context';

const RESPONSIVE = 'responsive' as const;
const INVALIDATE = 'invalidate' as const;

export type ComponentType =
Copy link

@kiner-tang kiner-tang Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里删掉了导出,可能会导致有从这里引入的地方报错,需要将迁移 RawItem 中的相关代码在这边也导出一下,如:

export type { ComponentType } from './RawItem'
export { OverflowContext } from './RawItem'

| React.ComponentType<any>
| React.ForwardRefExoticComponent<any>
| React.FC<any>
| keyof React.ReactHTML;
export { OverflowContext } from './context';

export type { ComponentType } from './RawItem';

export interface OverflowProps<ItemType> extends React.HTMLAttributes<any> {
prefixCls?: string;
Expand Down
9 changes: 7 additions & 2 deletions src/RawItem.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import * as React from 'react';
import classNames from 'classnames';
import Item from './Item';
import { OverflowContext } from './Overflow';
import type { ComponentType } from './Overflow';
import { OverflowContext } from './context';

export type ComponentType =
| React.ComponentType<any>
| React.ForwardRefExoticComponent<any>
| React.FC<any>
| keyof React.ReactHTML;

export interface RawItemProps extends React.HTMLAttributes<any> {
component?: ComponentType;
Expand Down
18 changes: 18 additions & 0 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';

export const OverflowContext = React.createContext<{
prefixCls: string;
responsive: boolean;
order: number;
registerSize: (key: React.Key, width: number | null) => void;
display: boolean;

invalidate: boolean;

// Item Usage
item?: any;
itemKey?: React.Key;

// Rest Usage
className?: string;
}>(null);