feat(utils): 添加批量更新相关的一个数据转换工具函数 normBulkUpdate#532
Open
Conversation
0ef61be to
ea6652f
Compare
ea6652f to
42c74c1
Compare
6245060 to
0ebcae5
Compare
0ebcae5 to
6613084
Compare
在批量接口使用 PUT 请求时,后端 response 上往往不会把所有更新的对象一
一罗列,而是以 `{ xxIds: Id[], ...updatedFields }` 的压缩形式呈现。这
样的数据是没办法直接更新到缓存层(RDB)的。
这里添加的 normBulkUpdate 函数可以用来将后端返回的这种压缩形式转换为缓
存层能接收的形式。如:
```
normBulkUpdate('taskIds', '_id')({
taskIds: ['123', '456'],
isArchived: true,
updated: '2018-08-21T05:43:10.000Z'
})
```
会得到
```
[
{_id: '123', isArchived: true, updated: '2018-08-21T05:43:10.000Z'},
{_id: '456', isArchived: true, updated: '2018-08-21T05:43:10.000Z'}
]
```
而在常见的 Observable response$ 上,则可以
```
response$.map(normBulkUpdate('taskIds', '_id'))
```
更多边界条件的行为定义,请见相应测试。
6613084 to
1bfe236
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
在批量接口使用 PUT 请求时,后端 response 上往往不会把所有更新的对象一
一罗列,而是以
{ xxIds: Id[], ...updatedFields }的压缩形式呈现。这样的数据是没办法直接更新到缓存层(RDB)的。
这里添加的 normBulkUpdate 函数可以用来将后端返回的这种压缩形式转换为缓
存层能接收的形式。如:
会得到
而在常见的 Observable response$ 上,则可以
更多边界条件的行为定义,请见相应测试。
/cc @coldfannn @aicest