Merged
docs:add a description of the callback interface in the README #25
docs:add a description of the callback interface in the README #25
Merged
liangtaoAdd on Oct 13
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`,参数说明如下:
cpf-manager

【AI-Review】【一般】【基础代码问题】【文档与实现不一致】 ● 问题: 回调签名与下方参数表的 Type/Description 与 OHOS 实现(harmony/mail/src/main/ets/RNMailTurboModule.ts)不一致:

  1. error 标注 Type: string,但实现中:
    • RNMailTurboModule.ts:69 成功分支调用 callback(null, 'sent'),error 实际为 null;
    • RNMailTurboModule.ts:76 同步 catch 分支调用 callback(e),error 为捕获的异常对象(非 string)。 实际类型为 string | null | Error,并非文档所述的 string。
  2. 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 当作 string 处理(如 error.length、error.includes()),在成功分支会对 null 抛 TypeError。
  • event 无取值说明,使用者无法编写基于事件名的分支逻辑(如判断是否发送成功),只能阅读源码确认。

● 建议:

  • error 的 Type 改为 string | null,或在描述中注明"成功时为 null,失败时为错误信息字符串";同时建议将实现侧 RNMailTurboModule.ts:76 的 callback(e) 改为 callback(e?.message ?? String(e)),使 error 在所有路径下均为 string,与文档一致。
  • event 的 Description 补充实际取值,例如"成功时为 'sent',失败时不传"。
likedislike
liangtao
liangtao
Oct 13 Comments:
likedislike
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:
cpf-manager

【AI-Review】【一般】【基础代码问题】【文档与实现不一致】 ● 问题: 回调签名与下方参数表的 Type/Description 与 OHOS 实现(harmony/mail/src/main/ets/RNMailTurboModule.ts)不一致:

  1. error 标注 Type: string,但实现中:
    • RNMailTurboModule.ts:69 成功分支调用 callback(null, 'sent'),error 实际为 null;
    • RNMailTurboModule.ts:76 同步 catch 分支调用 callback(e),error 为捕获的异常对象(非 string)。 实际类型为 string | null | Error,并非文档所述的 string。
  2. event 的 Description 为 "Event name",但未列出实际取值。实现中仅在成功时传入 '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 当作 string 处理(如 error.length、error.includes()),在成功分支会对 null 抛 TypeError。
  • event 无取值说明,使用者无法编写基于事件名的分支逻辑(如判断是否发送成功),只能阅读源码确认。

● 建议:

  • error 的 Type 改为 string | null,或在描述中注明"成功时为 null,失败时为错误信息字符串";同时建议将实现侧 RNMailTurboModule.ts:76 的 callback(e) 改为 callback(e?.message ?? String(e)),使 error 在所有路径下均为 string,与文档一致。
  • event 的 Description 补充实际取值,例如"成功时为 'sent',失败时不传"。
likedislike
liangtao
liangtao
Oct 13 Comments:
likedislike
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 Issues349## Known Issues
341 350