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

feat(utils): 添加批量更新相关的一个数据转换工具函数 normBulkUpdate #532

Open
wants to merge 1 commit into
base: release
Choose a base branch
from

Conversation

chuan6
Copy link
Contributor

@chuan6 chuan6 commented Aug 22, 2018

在批量接口使用 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'))

更多边界条件的行为定义,请见相应测试

/cc @coldfannn @aicest

@chuan6 chuan6 self-assigned this Aug 22, 2018
@chuan6 chuan6 requested a review from Saviio August 22, 2018 09:56
@chuan6 chuan6 force-pushed the feat/bulk-update-entityids branch 2 times, most recently from 0ef61be to ea6652f Compare August 22, 2018 10:01
@coveralls
Copy link

coveralls commented Aug 22, 2018

Coverage Status

Coverage increased (+0.03%) to 95.969% when pulling 1bfe236 on feat/bulk-update-entityids into b919cde on release.

@chuan6 chuan6 changed the title feat(utils): 添加批量更新相关的一个数据转换工具函数 normBulkUpdate WIP feat(utils): 添加批量更新相关的一个数据转换工具函数 normBulkUpdate Aug 22, 2018
@chuan6 chuan6 changed the title WIP feat(utils): 添加批量更新相关的一个数据转换工具函数 normBulkUpdate feat(utils): 添加批量更新相关的一个数据转换工具函数 normBulkUpdate Aug 22, 2018
@chuan6 chuan6 force-pushed the feat/bulk-update-entityids branch 5 times, most recently from 6245060 to 0ebcae5 Compare August 23, 2018 01:42
在批量接口使用 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'))
```

更多边界条件的行为定义,请见相应测试。
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