Skip to content
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

docs: subclassing.md #49

Merged
merged 2 commits into from
May 9, 2021
Merged

docs: subclassing.md #49

merged 2 commits into from
May 9, 2021

Conversation

ai-xiaihai
Copy link
Contributor

No description provided.

@vercel
Copy link

vercel bot commented Mar 4, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/mobx-docs-cn/zh-mobx-js-org/8u29bEMsuuPQDEvChsSgt1uj5tRg
✅ Preview: https://zh-mobx-js-org-git-fork-ai-xiaihai-patch-1-mobx-docs-cn.vercel.app

@ai-xiaihai
Copy link
Contributor Author

@iChenLei 已完成对subclassing.md的翻译,麻烦校对啦,谢谢

@iChenLei iChenLei added 校对中 文档翻译完成,需要至少一个同学进行review校对 and removed 翻译中 文档正在翻译中 labels Mar 6, 2021
@iChenLei
Copy link
Member

iChenLei commented Mar 6, 2021

@ai-xiaihai ❤️ 感谢您的辛苦翻译。 cc @WanderWang @wangjq4214

subclassing是6.1.0之后的breaking change,是比较新的内容, PR可见mobxjs/mobx#2641


Subclassing is supported with [limitations](#limitations). Most notably you can only **override actions/flows/computeds on prototype** - you cannot override _[field declarations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#field_declarations)_. Use `override` annotation for methods/getters overriden in subclass - see example below. Try to keep things simple and prefer composition over inheritance.
对使用子类的支持是有[限制](#limitations)的. 最值得注意的一点是你只能 **在原型里重新定义actions/flows/computeds** - 你不能重新定义 _[字段声明](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#field_declarations)_. 在子类中请使用 `override` 注释被重新定义的methods/getters - 见下例。 请凡事从简,并优先考虑组合(而非继承)。
Copy link
Contributor

Choose a reason for hiding this comment

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

重新定义原型中的 actions/flows/computeds

是否好一点

1. [All other limitations apply as well](observable-state.html#limitations)
1. 只有定义在**原型**上的 `action`, `computed`, `flow`, `action.bound` 可以在子类中被 **重新定义**。
1. 不能在子类中重新注释字段(`override` 除外)。
1. `makeAutoObservable` 不支持子类的使用.
Copy link
Contributor

Choose a reason for hiding this comment

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

不支持在子类中使用。

标点

1. 只有定义在**原型**上的 `action`, `computed`, `flow`, `action.bound` 可以在子类中被 **重新定义**。
1. 不能在子类中重新注释字段(`override` 除外)。
1. `makeAutoObservable` 不支持子类的使用.
1. 不支持扩展内置(`ObservableMap`, `ObservableArray`, 等)。
Copy link
Contributor

Choose a reason for hiding this comment

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

不支持扩展内置数据结构(ObservableMap, ObservableArray, 等)。

使用中文括号?

1. 不能在子类中重新注释字段(`override` 除外)。
1. `makeAutoObservable` 不支持子类的使用.
1. 不支持扩展内置(`ObservableMap`, `ObservableArray`, 等)。
1. 你不能在子类中给`makeObservable` 提供不同选项。
Copy link
Contributor

Choose a reason for hiding this comment

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

你不能在子类中给 makeObservable 提供不同选项。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

看起来和原来的一样 🤔 是typo吗?

Copy link
Member

Choose a reason for hiding this comment

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

我也没看出来区别 😂

Copy link
Contributor

Choose a reason for hiding this comment

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

加了个空格🤣

Copy link
Contributor Author

Choose a reason for hiding this comment

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

请问, 对于

  1. 中文中的 英文,
  2. 中文中的 小段代码
    前后要不要加空格, 有没有什么统一的标准?


### `TypeError: Cannot redefine property`

If you see this, you're probably trying to **override arrow function** in subclass `x = () => {}`. That's not possible because **all annotated** fields of classes are **non-configurable** ([see limitations](observable-state.md#limitations)). You have two options:
如果你遇见这一错误, 你可能正在子类中**重新定义箭头函数** `x = () => {}`. 其不可行的原因是**一切被注释的** 类字段都是**不可配置的** ([详见限制](observable-state.md#limitations)). 你有以下这两个选择:
Copy link
Contributor

Choose a reason for hiding this comment

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

遇见=>遇到 是不是更书面一点


### `TypeError: Cannot redefine property`

If you see this, you're probably trying to **override arrow function** in subclass `x = () => {}`. That's not possible because **all annotated** fields of classes are **non-configurable** ([see limitations](observable-state.md#limitations)). You have two options:
如果你遇见这一错误, 你可能正在子类中**重新定义箭头函数** `x = () => {}`. 其不可行的原因是**一切被注释的** 类字段都是**不可配置的** ([详见限制](observable-state.md#limitations)). 你有以下这两个选择:
Copy link
Contributor

Choose a reason for hiding this comment

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

加粗文字两侧是否有空格是否需要统一一下呢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

参照其他几个在校对中的PR,我会把空格都去掉 🚀

@ai-xiaihai
Copy link
Contributor Author

我已经依照评论做了更改, 内容在第二个commit中 🎉

@iChenLei iChenLei merged commit 415f55d into mobxjs:main May 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
校对中 文档翻译完成,需要至少一个同学进行review校对
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants