meteor-astronomy
meteor-astronomy copied to clipboard
Events not firing
For some reason, the only events I can get to fire are the init events. Here's what my code looks like:
// in a server method
import {Team} from '../Teams';
const leagueTeams = Team.find({ Leagues: { $in: [league._id] } });
leagueTeams.forEach((team) => {
//does a bunch of stuff
team.save()
});
// in Teams.js
import { Class } from 'meteor/jagi:astronomy';
const Teams = Class.create({
name: 'Team',
collection: Teams,
fields: {
// a bunch of fields
},
events: {
afterInit(e) {
const team = e.currentTarget;
console.log('init', team);
},
beforeSave(e) {
console.log('before save', e.currentTarget);
},
beforeInsert() {
console.log('inserted');
},
beforeUpdate() {
console.log('updated');
},
afterSave() {
console.log('after save');
},
},
}
export {Team};
The only one that fires is init. Any idea why? The collection is a scorpius collection with simple-schema attached (overkill I know), so perhaps that's related? I'm having a tough time implementing a calculated field.
Ah, nevermind. I think you have some clever dif
checker in there somewhere, save doesn't actually get called unless the document has changed. Is this a bug or a feature?
It's a feature, you shouldn't invoke operation if it's not needed. So if there are no modifications then operation won't be executed. Btw. I see some bugs in your example code but I assume that you just made some typos pasting code.
What did I miss?
For example you're importing Team
instead Teams
collection:
import {Team} from '../Teams';
Later you create class Teams
instead of Team
:
const Teams = Class.create({
name: 'Team',
collection: Teams,
and you passed Teams
to the collection
property which is undefined
in this example.