-
Notifications
You must be signed in to change notification settings - Fork 84
refactor: typescript implement #148
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
Conversation
node rollup.js | ||
node node_modules/.bin/postcss -o style/index.css src/styles/index.css | ||
node scripts/fix-css.js style/index.css | ||
rm -rf cjs/ && tsc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
恐怕我们不能现在就改成tsc
编译。之前版本是一个bundle,它可以直接用于<script>
引入等方式,而tsc
的产物并不是打包的,这会是一个BREAKING
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你觉得应该怎么处理?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在这个大版本中,乖乖保留原来的rollup
构建吧,下个大版本改为tsc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rollup 怎么生成 d.ts 啊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
版本控制可以交给你,我这个能发个 3.0-alpha.0 就好?
我想你后续对 3.0 也有很多构想吧。你可以在这个基础上搞。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
让tsc
生成定义,然后用rollup
生成bundle,这样行不?入口是index.js -> index.d.ts
,能对上应该就没问题
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可能的问题
- dependencies 要不要加上,因为可能会依赖他们的类型
- import {xxx} from 'react-diff-view/es/tokenize' 会被 ts 支持,但是 js 不支持,因为类型好像必须是 esm 的,没法合起来,不过也许可以只覆盖一个 index.js,其他的还是 esm?不知道 script 引入的要求是什么?
@@ -19,6 +26,7 @@ const UnifiedDecoration = ({hideGutter, className, gutterClassName, contentClass | |||
); | |||
} | |||
|
|||
// @ts-ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是children
的类型问题?这个类型能不能再强化一下,弄成tuple的话,jsx能不能认出来……
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该只是 ts 类型推断上的问题,Children.count() 不会有推导,实际是对的,所以 ignore 了,不影响使用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
viewType, | ||
gutterType = 'default', | ||
selectedChanges = [], | ||
widgets = {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里个[]
和{}
,最好放外面定义个常量?不然用默认值的时候,每次都是新对象,而react-diff-view
整个性能非常依赖memo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
import {createContext, useContext} from 'react'; | ||
|
||
interface Context { | ||
gutterType: 'default' | 'none' | 'anchor'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这几个string literal union感觉应该是单独的类型,用到的地方不少
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
viewType: 'unified' | 'split'; | ||
selectedChanges: string[]; | ||
monotonous: boolean; | ||
widgets: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用Record<string, ReactNode>
是不是比较好
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
widgets: { | ||
[key: string]: any; | ||
}; | ||
renderGutter: () => any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
返回应该是ReactNode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
type: 'insert'; | ||
content: string; | ||
isInsert: true; | ||
isDelete?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里应该固定值,没有或者false
吧,都知道是insert
了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里严格会导致需要改代码,就不是初衷了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有道理
|
||
export type Change = InsertChange | DeleteChange | NormalChange; | ||
|
||
export interface HunkType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个类型的命名我有点想法,一般XxxType
会给人是一种枚举的感觉,叫HunkInfo
之类的会不会更好,下同
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以
isBinary: boolean; | ||
// 'rename' 和 'copy' 理论上存在但实际很少用到 | ||
type: 'add' | 'delete' | 'modify' | 'rename' | 'copy'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多了空行
generateAnchorID?: (change: Change) => any; | ||
selectedChanges?: string[]; | ||
tokens?: any[] | null; | ||
widgets?: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
统一用Record
吧,我记得我们的TS lint规则里有一条这个,只是react-diff-view
现在没用我们的规则
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好像没有,我从内部挪过来的
@@ -57,7 +64,7 @@ const findNearestNormalChangeIndex = ({changes}, start) => { | |||
return -1; | |||
}; | |||
|
|||
const splitRangeToValidOnes = (hunks, start, end) => { | |||
const splitRangeToValidOnes = (hunks: HunkType[], start: number, end: number): Array<[number, number]> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把[number, number]
拉出来造一个Range
的类型更有语义
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 PR 不会改语义,合入之后可以改。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我的意思是,放一个type Range = [number number]
,在类型上更有可读性
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哦,明白了
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Up!!! |
👀 |
I decide to move all implementation to TypeScript and publish version 2 with some small breaking changes, please track #189 for progress. |
Working in Progress
Do not merge.
This will let us provide
d.ts
in nextmajor
orminor
release. #135Something will include in this PR
site
Something will not include in this but in next PR
recompose
@testing-libary/react-hooks
to add some tests