• Stars
    star
    497
  • Rank 88,652 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 11 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⚙️ Meteor package that allows you to define helpers on your collections

Meteor Collection Helpers

Collection helpers automatically sets up a transformation on your collections using Meteor's Mongo.Collection transform option, allowing for simple models with an interface that's similar to template helpers.

Installation

$ meteor add dburles:collection-helpers

Usage

Write your helpers somewhere seen by both client and server.

Books = new Mongo.Collection('books');
Authors = new Mongo.Collection('authors');

Books.helpers({
  author() {
    return Authors.findOne(this.authorId);
  }
});

Authors.helpers({
  fullName() {
    return `${this.firstName} ${this.lastName}`;
  },
  books() {
    return Books.find({ authorId: this._id });
  }
});

This will then allow you to do:

Books.findOne().author().firstName; // Charles
Books.findOne().author().fullName(); // Charles Darwin
Authors.findOne().books()

Our relationships are resolved by the collection helper, avoiding unnecessary template helpers. So we can simply write:

Template.books.helpers({
  books() {
    return Books.find();
  }
});

...with the corresponding template:

<template name="books">
  <ul>
    {{#each books}}
      <li>{{name}} by {{author.fullName}}</li>
    {{/each}}
  </ul>
</template>

Meteor.users

You can also apply helpers to the Meteor.users collection

Meteor.users.helpers({
  // ...
});

Applying the transformation function

Sometimes it may be useful to apply the transformation directly to an object.

var doc = {
  firstName: 'Charles',
  lastName: 'Darwin'
};

var transformedDoc = Authors._transform(doc);

transformedDoc.fullName(); // Charles Darwin

License

MIT

More Repositories

1

meteor-google-maps

🗺 Meteor package for the Google Maps Javascript API v3
JavaScript
196
star
2

meteor-presence

👥 Meteor package to help track users' presence
JavaScript
87
star
3

meteor-two-factor

🔐 Two factor authentication package for accounts-password
JavaScript
81
star
4

meteor-spacebars-tohtml

Meteor package to ease rendering spacebars to html
JavaScript
36
star
5

mystical

🌌 A CSS-in-JS library for constraint based design
JavaScript
32
star
6

reactive-maps-example

Example Meteor application demonstrating a reactive Google map
JavaScript
29
star
7

meteor-google-maps-react-example

An example of using the Meteor package dburles:meteor-google-maps with React
JavaScript
20
star
8

meteor-guide-starter-react

A basic starter application based on the Meteor guide
JavaScript
20
star
9

geolocation-example

JavaScript
20
star
10

flow-router-react-example

Flow Router and React example
JavaScript
19
star
11

meteor-capture-pubsub2

A Meteor project demonstrating publishing data from an external API
JavaScript
16
star
12

load-more-list

Meteor application demonstrating a paginated list component
JavaScript
15
star
13

meteor-flow-router-map

Meteor package for Flow Router
JavaScript
15
star
14

meteor-google-maps-demo

Demo project for meteor-google-maps package
JavaScript
13
star
15

meteor-capture-incoming

A Meteor project demonstrating a Twitter style incoming posts dialog
JavaScript
12
star
16

flow-router-blaze-example

Flow Router and Blaze example
JavaScript
11
star
17

two-factor-example

JavaScript
9
star
18

treel

A Meteor application
JavaScript
9
star
19

react-tiny-state

Tiny React global state containers
JavaScript
8
star
20

meteor-eslint

Meteor eslint package
JavaScript
7
star
21

meteor-capture-modal-example

A Meteor project demonstrating a basic modal pattern
JavaScript
6
star
22

ssu16

SSU16: Sound Sequencing Unit
JavaScript
6
star
23

recompose-forms

JavaScript
6
star
24

reactive-relations

Intelligent reactive relational publications for Meteor
JavaScript
6
star
25

meteor-packery

Meteor package for Packery layout library
JavaScript
5
star
26

graphql-client

A simple GraphQL client with cache
JavaScript
4
star
27

bookstore

JavaScript
4
star
28

cellar

A wine cellar app made with Meteor
JavaScript
3
star
29

meteor-react-base

☄️Meteor and ⚛️ React example/base starter app
JavaScript
3
star
30

meteor-session-unset

JavaScript
3
star
31

meteor-capture-pubsub

A Meteor project demonstrating publishing data that doesn't come from Mongo
JavaScript
3
star
32

parcel-react-base

📦 Parcel and ⚛️ React example/base starter app
JavaScript
3
star
33

vcvm

VCV Rack modules explorer
JavaScript
2
star
34

diy-graphql-server

A simple but fully functional GraphQL server in pure ESM
JavaScript
2
star
35

awesome-chat

A live chat app build demonstrated at Melb Meteor 9
JavaScript
2
star
36

meteor-lazy

Meteor package for lazy developers
JavaScript
2
star
37

meteor-dogescript

JavaScript
2
star
38

route2

🔗 A simple client side router with React support
JavaScript
2
star
39

simple-meteor-react-demo

JavaScript
2
star
40

conduit-example

JavaScript
2
star
41

webpack4-react-base

JavaScript
2
star
42

react-shared-usestate

Create global React useState hooks
JavaScript
2
star
43

meteor-conduit

JavaScript
1
star
44

snowpack-react-base

JavaScript
1
star
45

spacex

JavaScript
1
star
46

meteor-school

JavaScript
1
star
47

storybook-dynamic-import-issue

JavaScript
1
star
48

base-app

JavaScript
1
star
49

meteor-presence-live-caret

JavaScript
1
star
50

meteor-lint-config-example

JavaScript
1
star
51

chrome-tab-popup

A chrome extension that provides a clean and simple popup list to switch open tabs
JavaScript
1
star
52

route2-example

Example app for https://github.com/dburles/route2
JavaScript
1
star
53

state-forms

JavaScript
1
star
54

whiski

JavaScript
1
star
55

query-array-demo

Demo application for Meteor Iron Router Query Array package
JavaScript
1
star
56

meteor-stringify-pretty

JavaScript
1
star
57

deno-ssr-url-modules-experiment

JavaScript
1
star
58

scoped-style-components

Lightweight React components for scoping styles natively. CSS-in-JS without the runtime!
TypeScript
1
star