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

Commits on Sep 13, 2018

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

    在批量接口使用 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'))
    ```
    
    更多边界条件的行为定义,请见相应测试。
    chuan6 committed Sep 13, 2018
    Configuration menu
    Copy the full SHA
    1bfe236 View commit details
    Browse the repository at this point in the history