/imports/api/task.js
import { Mongo } from 'meteor/mongo';
export const Tasks = new Mongo.Collection('tasks');
if (Meteor.isServer) {
// This code only runs on the server
Meteor.publish('tasks', function tasksPublication() {
return Tasks.find();
});
}
/server/main.js
import { Meteor } from 'meteor/meteor';
import '/imports/api/tasks';
Meteor.startup(() => {
// code to run on server at startup
Meteor.publish('allUsers',() => {
return Meteor.users.find();
});
});
/imports/ui/App.js
import React, {Component} from 'react';
import {withTracker} from 'meteor/react-meteor-data';
import {Tasks} from '/imports/api/tasks';
class App extends Component {
render() {
return (
<div>
App
</div>
);
}
}
export default withTracker(props => {
// Do all your reactive data access in this method.
// Note that this subscription will get cleaned up when your component is unmounted
const handles = [
Meteor.subscribe('tasks', props.id),
Meteor.subscribe('allUsers')
];
const loading = handles.some(handle => !handle.ready());
console.log('loading',loading);
return {
currentUser: Meteor.user(),
listLoading: loading,
tasks: Tasks.find({listId: props.id}).fetch(),
};
}
)(App);