-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Surface code review #4
Comments
The
|
Regarding 9th point. I meant that this code block let cssClassProp = { cssClass: ‘’ };
if (c.cellClass) {
if (typeof c.cellClass === ‘string’) {
cssClassProp = { cssClass: c.cellClass };
} else if (Array.isArray(c.cellClass)) {
cssClassProp = { cssClass: c.cellClass.join(' ’) };
} else if (typeof c.cellClass === ‘function’) {
const params: CellClassParams = getCellParams(row, c, rowIndex, value, api!.current!);
cssClassProp = { cssClass: c.cellClass(params) as string };
}
}
could be transformed into the reusable function call to improve readability and self-documenting. const cssClassProp = parseColumnCssClass(c.cellClass) This like one of the most basic principles of functional programming (which I am a fan of, so you could ignore my reviews XD). In functional programming, we are writing not what our code should do but how it works. For instance, in this example, I need to read and think some time to understand that this code block is actually parsing class name because it can be array or function or string. |
@dmtrKovalenko I should have consolidated your feedback into new issues and #6. If you see something missing, please open a new issue per item, thanks for giving a 👁️ :). |
Here are some of my foundings on the current
material-ui-x
codebase.clsx
module to combine class namesSuch expressions are so unreadable (https://github.com/mui-org/material-ui-x/blob/master/packages/grid/src/components/cell.tsx#L6):
className={'country-flag'}
are a little bit weird.Which is potentially caused by 1.
React.memo
? Memoization costs runtime performance. And probably we do not need to make premature optimizations:Avoid using inline styles
style={{ display: 'flex', justifyContent: 'space-between' }}
(https://github.com/mui-org/material-ui-x/blob/master/packages/grid-data-generator/src/renderer/incoterm-renderer.tsx, https://github.com/mui-org/material-ui-x/blob/master/packages/grid-data-generator/src/renderer/progress-bar.tsx and other)Grid cell
field
prop must be well-typed string union which will autocomplete the other available props (https://github.com/mui-org/material-ui-x/blob/master/packages/grid/src/components/cell.tsx#L6)Make sure that we are using
strict
mode intsconfig.json
. I am seeing some functions without argument types, that would be inferred as anyExpressions like
icons: { [key: string]: React.ReactElement };
are so unsafe.key
must be well-typed for autocomplete and type system experience(https://github.com/mui-org/material-ui-x/blob/master/packages/grid/src/components/column-headers.tsx#L13)
Probably we need some convention about the body of the functional component. IMHO it is much more readable when all the state/ref hooks are going first, then declaring effects, then callbacks and than
return
. It is similar to what we have with class components (1. state in the constructor, 2. methods, and the lastrender
method) E.g. this component is really hard to read.Avoid using 1-letter variable names, even for maps
{columns.map((c, idx) => (
(https://github.com/mui-org/material-ui-x/blob/master/packages/grid/src/components/column-headers.tsx#L94)This .map loop is to long and too nested. Really hard to read, probably need to split in some reusable functions to improve readability.
Do we really need constants for css classes? Looks like it is too different from
material-ui
styling solution (https://github.com/mui-org/material-ui-x/blob/master/packages/grid/src/constants/cssClassesConstants.ts)Events must be properly typed
MouseEvent
is native dome event.React.MouseEvent
is react synthetic event and must be used asReact.MouseEvent<HTMLElement>
to prevent explicit casts later on and improve typings. (https://github.com/mui-org/material-ui-x/blob/master/packages/grid/src/hooks/root/useApi.ts#L58Overall typescript doesn't work well right from what I am seeing. For example probably we want to use
import * as React from 'react'
in this project as well to get better access to the react typings.Probably we don't need to use explicit type definitions everywhere like here:
We could make the return value to be inferred automatically. The same for anonym objects.
It is used
!
operator really rarely which means that we have an unsound type system and we are going to crash here 😱 just like here. Probably we want to use?
operator?Do we really need to use
forceUpdate
's in each hook? Probably we can avoid using it?Do we need to duplicate
ColumnsContainer.displayName = 'ColumnsContainer';
for each component? It will be inferred by react automaticallyIs it intended that we are using global classnames? I suppose we need to remove usage of the global class names like here. It is potentially dangerous because of accidental overrides. But I suppose it will be redone.
Probably we need to use
prettier
for code formatting, to increase readability for other contributors.The text was updated successfully, but these errors were encountered: