Skip to content

[Refactor] typescript#5

Open
ole3021 wants to merge 3 commits intomasterfrom
refactor-typescript
Open

[Refactor] typescript#5
ole3021 wants to merge 3 commits intomasterfrom
refactor-typescript

Conversation

@ole3021
Copy link
Owner

@ole3021 ole3021 commented Aug 9, 2018

No description provided.

Copy link

@bgdsh bgdsh left a comment

Choose a reason for hiding this comment

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

总的来说挺好的。我个人习惯一个类,一个接口各自占一个文件,找起来方便一些。

"watch": "jest --watchAll"
"lint": "tslint -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
"prebuild": "rimraf dist",
"build": "tsc --module commonjs && rollup -c rollup.config.ts && typedoc --out docs --target es6 --theme minimal --mode file src",
Copy link

Choose a reason for hiding this comment

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

build的配置最好写进tsconfig.json

Copy link
Owner Author

Choose a reason for hiding this comment

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

好的, 配置的我还没弄, 这个从https://github.com/alexjoverm/typescript-library-starter 这里抄来的
回头好好整理一下。

Copy link

Choose a reason for hiding this comment

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

好的。

meta: object
}

interface IBlogModule {
Copy link

Choose a reason for hiding this comment

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

感觉这个IBlogModule多此一举。没看到在别的地方用。

Copy link
Owner Author

Choose a reason for hiding this comment

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

是我没用对 我在Index里 应该规定接口, 而不是直接引用类。


build(blogs: IBlog[]): void {
const rootPath = getRootPath()
saveToFile(path.join(rootPath, this.fileName), JSON.stringify(blogs))
Copy link

Choose a reason for hiding this comment

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

直接序列化一个数组感觉不太好, 感觉应该是这样{blogs}

Copy link
Owner Author

Choose a reason for hiding this comment

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

why? json本身也可以是数组啊。

Copy link

Choose a reason for hiding this comment

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

嗯,我查了一下规范,你说的对。

) => {
const itemPath = path.join(pathLike as string, name)
if (checkIsDirectory(itemPath)) {
return allItems.concat(getDirFileInfo(itemPath, root) as string[])
Copy link

Choose a reason for hiding this comment

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

不能统一成IFileInfo[]么

Copy link
Owner Author

Choose a reason for hiding this comment

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

这因为有个reduce, 我把reduce单独拆出去,这样就不用使用 两种类型了。

Copy link

Choose a reason for hiding this comment

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

好的。

public readonly size: number
public readonly meta: object

constructor(fileInfo: IFileInfo) {
Copy link

Choose a reason for hiding this comment

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

这里看起来不是太好拓展,建议写一个IBlogOptions接口,fileInfo是其中的一个成员。

Copy link
Owner Author

Choose a reason for hiding this comment

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

嗯 明白。

public readonly createdAt: Date
public readonly updatedAt: Date
public readonly size: number
public readonly meta: object
Copy link

Choose a reason for hiding this comment

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

感觉用了object和不写类型差不多,最好把meta的类型定义一下。

Copy link
Owner Author

Choose a reason for hiding this comment

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

meta是这个样子的, 是github markdown上边的一段yaml, 里面写什么字段我并不知道, 或者说用户写什么他自己清楚,他自己会用就可以了。
https://github.com/ole3021/gh-blogs/blame/refactor-typescript/test/fixture/about.md#L4

这个我也不知道怎么办, 在测试的时候 编辑器还会报错。
https://github.com/ole3021/gh-blogs/blob/refactor-typescript/test/unit/blogs.spec.ts#L24

Copy link
Owner Author

Choose a reason for hiding this comment

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

有什么好建议没有?

Copy link

Choose a reason for hiding this comment

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

把能确定的部分都写进去。比如可能有哪些字段,可能有哪些取值。

Copy link
Owner Author

Choose a reason for hiding this comment

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

可以。。

@ole3021
Copy link
Owner Author

ole3021 commented Aug 9, 2018

mvc呗?扔到一个目录里?有什么代码可以参考一下。

@bgdsh
Copy link

bgdsh commented Aug 9, 2018

这句话啥意思?

Repository owner deleted a comment from liuzhebaba Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants