collection icon indicating copy to clipboard operation
collection copied to clipboard

Collection.gather requires identical names for values of type Item and Stream<Item>

Open bbarker opened this issue 8 years ago • 2 comments

While using something like Collection.gather(Task, sources, fetchedTasks$, 'uid') , I have to make sure fetchedTasks$ has objects where the property item is actually named item$. No idea why. This requires me to use a transformer like this:

function crazyHack(subCols: Stream<SubForCollection[]>): Stream<any> {
  return subCols.map( scs => scs.map(sc => {
    return {
      // For some reason, Collection wants submission to
      // be named submission$
      submission$: sc.submission,
      submission_id: sc.submission_id
    };
  }))

I then call e.g., Collection.gather(Task, sources, crazyHack(fetchedTasks$), 'uid').

This happened during an automatic refactor of naming submission to the more appropriate submission$ and took me hours to find, so I would advocate removing this dependence if possible.

bbarker avatar Feb 10 '17 01:02 bbarker

gather uses the keys from snapshot object as keys for sources: https://github.com/cyclejs/collection/blob/master/src/collection.js#L201. I don't think it should append dollar sign automatically, but maybe it could accept a transformKey: (String) => String function as an argument

Hypnosphi avatar Feb 10 '17 10:02 Hypnosphi

That sounds reasonable to me!

bbarker avatar Feb 10 '17 14:02 bbarker