data-point
data-point copied to clipboard
Handle ReducerEntity#asCollection with a ReducerMap
Problem description:
ReducerEntity supports asCollection notation (e.g. hash:example[]), but the code for resolving that notation is very similar to ReducerMap:
https://github.com/ViacomInc/data-point/blob/master/packages/data-point/lib/entity-types/base-entity/resolve.js#L206
Suggested solution:
Remove the asCollection property from ReducerEntity. Instead, if the [] notation is used, a ReducerMap should be created. That can be done by adding this code to the ReducerEntity create function (https://github.com/ViacomInc/data-point/blob/master/packages/data-point/lib/reducer-types/reducer-entity/factory.js#L44):
if (source.endsWith('[]')) {
return createReducerMap(createReducer, source.replace(/\[]$/, ''))
}
This would simplify the BaseEntity#resolve function, because it wouldn't need to handle asCollection or use Promise.map.