Merged
docs:add a description of the callback interface in the README #25
liangtaoAdd on Oct 13
docs:add a description of the callback interface in the README #25
Merged
Total: 2 files changed+18-0
| @@ -335,6 +335,15 @@ Mailer.mail({ | |||
| 335 | | isHTML | 邮件内容是否为 html | boolean | no | all | no | | 335 | | isHTML | 邮件内容是否为 html | boolean | no | all | no | |
| 336 | | attachments | 附件信息 | object[] | no | all | no | | 336 | | attachments | 附件信息 | object[] | no | all | no | |
| 337 | 337 | ||
| 338 | +#### callback | ||
| 339 | + | ||
| 340 | +结果回调函数,签名为 `(error: string, event?: string) => void`,参数说明如下: | ||
| 341 | + | ||
| 342 | +| Name | Description | Type | Required | Platform | HarmonyOS Support | | ||
| 343 | +| ----- | ----------- | ------ | -------- | -------- | ----------------- | | ||
| 344 | +| error | 错误信息 | string | yes | all | yes | | ||
| 345 | +| event | 事件名称 | string | no | all | yes | | ||
| 346 | + | ||
| 338 | ## 遗留问题 | 347 | ## 遗留问题 |
| 339 | 348 | ||
| 340 | - [ ] 不支持 attachments 附件传递: [issue#1](https://github.com/react-native-oh-library/react-native-mail/issues/1) | 349 | - [ ] 不支持 attachments 附件传递: [issue#1](https://github.com/react-native-oh-library/react-native-mail/issues/1) |
| @@ -336,6 +336,15 @@ Mailer.mail({ | |||
| 336 | | isHTML | Whether the email body is HTML | boolean | no | all | no | | 336 | | isHTML | Whether the email body is HTML | boolean | no | all | no | |
| 337 | | attachments | Attachment information | object[] | no | all | no | | 337 | | attachments | Attachment information | object[] | no | all | no | |
| 338 | 338 | ||
| 339 | +#### callback | ||
| 340 | + | ||
| 341 | +The result callback function has the signature `(error: string, event?: string) => void`, with parameters described below: | ||
【AI-Review】【一般】【基础代码问题】【文档与实现不一致】 ● 问题: 回调签名与下方参数表的 Type/Description 与 OHOS 实现(harmony/mail/src/main/ets/RNMailTurboModule.ts)不一致:
触发路径: ● 影响:
● 建议:
![]() ![]() | |||
| 342 | + | ||
| 343 | +| Name | Description | Type | Required | Platform | HarmonyOS Support | | ||
| 344 | +| ----- | ------------- | ------ | -------- | -------- | ----------------- | | ||
| 345 | +| error | Error message | string | yes | all | yes | | ||
| 346 | +| event | Event name | string | no | all | yes | | ||
| 347 | + | ||
| 339 | 348 | ||
| 340 | ## Known Issues | 349 | ## Known Issues |
| 341 | 350 | ||


【AI-Review】【一般】【基础代码问题】【文档与实现不一致】 ● 问题: 回调签名与下方参数表的 Type/Description 与 OHOS 实现(harmony/mail/src/main/ets/RNMailTurboModule.ts)不一致:
error标注 Type: string,但实现中:callback(null, 'sent'),error 实际为 null;callback(e),error 为捕获的异常对象(非 string)。 实际类型为string | null | Error,并非文档所述的 string。event的 Description 为"事件名称",但未列出实际取值。实现中仅在成功时传入'sent'(RNMailTurboModule.ts:69),失败/异常时为 undefined。触发路径:
Mailer.mail(options, callback)→RNMailTurboModule.mail()→startEmailApp()→startAbility().then(() => callback(null, 'sent'))(error=null)/.catch(err => callback(err.message))(error=string)/catch(e) { callback(e) }(error=异常对象)。● 影响:
error.length、error.includes()),在成功分支会对 null 抛 TypeError。● 建议:
string | null,或在描述中注明"成功时为 null,失败时为错误信息字符串";同时建议将实现侧 RNMailTurboModule.ts:76 的callback(e)改为callback(e?.message ?? String(e)),使 error 在所有路径下均为 string,与文档一致。