ecomfe / standard-redux-shape

A library to help standardize your redux state shape
MIT License
47 stars 6 forks source link

Allow one withTableUpdate to update multiple entity tables #5

Closed otakustay closed 6 years ago

otakustay commented 6 years ago

This requires to change current withTableUpdate(tableName, selectEntities) to withTableUpdate(selectEntities, [tableName])

By this change of design, we allow selectEntities to return multiple table patches when tableName is not provided, in this case selectEntities should return an object like:

{
  usersByID: {
    123: {...},
    456: {...}
  },
  postsByName: {
    foo: {...},
    bar: {...}
  }
}

By the time an object with multiple table patches are returned, multiple UPDATE_ENTITY_TABLE actions are dispatched (or we just dispatch one UPDATE_MULTIPLE_ENTITY_TABLES action, we can discuss it)

This involves a breaking change of API so we need to publish version 0.6.0

yuxuan commented 6 years ago

如果我理解正确的话,当tableName为空时,selectEntities是要强制

{
  usersByID: {
    123: {...},
    456: {...}
  },
  postsByName: {
    foo: {...},
    bar: {...}
  }
}

这种格式的,对吧?然后每个key作为要更新的table?这种强制的话需要验证判断么?比如如果没有按照这种格式的话,我只返回了对象:

{
   123: {...},
   456: {...}
}

我理解,现在的withTableUpdate,selectEntities应该就是返回的这种单一的entity。这样更新的话,会把123,456作为tableName来更新的吧

还有就是,如果tableName给出了的话,selectEntities是否应该也要返回与tableName相对应的key?比如:上面的例子,selectEntities返回那样一个对象,tableNames需要是['usersById', 'postsByName'] ?

otakustay commented 6 years ago

这种格式的,对吧

是的,必须这种格式。如果变成下面的形式,就会产生出123这样的实体表,这是符合预期的

如果tableName给出了的话,selectEntities是否应该也要返回与tableName相对应的key

tableName给了的时候,保持和现在版本一致的逻辑,selectEntiteis返回的对象中就是123、456这些

otakustay commented 6 years ago

Fixed via #7