dburles / meteor-collection-helpers

⚙️ Meteor package that allows you to define helpers on your collections
https://atmospherejs.com/dburles/collection-helpers
MIT License
498 stars 33 forks source link

Idea: access parent cursor in doc helpers #40

Open gwendall opened 9 years ago

gwendall commented 9 years ago

That would be pretty useful to be able to access the parent cursor from a document returned to the helpers method, and in particuler its previous / next docs in the cursor.

That would make things like grouping elements by an attribute very clean. Examples: for a chat app where you would need to insert a separator for each day, a contacts list where you need to group people by the first letter of their names, etc.

The code could look like this:

Messages.helpers({
  '$newDay': funtion(prev, next) {
    return (!prev || (this.day !== prev.day)) ? this.day : null;
  }
});

Haven't been able to dig into minimongo yet - but @dburles do you think this is something that can be done?

dburles commented 9 years ago

Interesting idea @gwendall. I haven't looked into anything like this yet.