I have a Collection that includes a property of foo. However, foo is also a CollectionHelper method.
i.e. const CollectionSchema = new SimpleSchema({ foo: { type: String }
and then
Collection.helpers({
foo: function () { return someLogic }
});
My problem is that I call Document.foo. Note that I leave out the () to denote I’m trying to access the property and not call the method i.e. Document.foo().
This works fine if foo exists on the Document. Otherwise I get
If it’s not too big a change for your project, I’d suggest using static helpers instead.
So instead of wrapping documents with a class/prototype with methods on each document, you pass the document into the methods of a separate class:
// Instead of
const document = Collection.findOne({ foo: "bar" });
document.foo()
// Use a separate class
import { BarHelpers } from '/api/bar';
const document = Bar.findOne({ foo: "bar" });
BarHelpers.foo(document);
The separation of concerns makes it easier to reason about your documents (they are just the data) and test the helpers in isolation.
Also never have to worry about naming clashes
Please note that this is my personal preference and is not prescriptive. Just advising on what I do differently that avoids the original issue