kadirahq / mantra

Mantra - An Application Architecture for Meteor
https://kadirahq.github.io/mantra/
978 stars 52 forks source link

server/publications/collectionname.js not Being Called? #159

Closed VikR0001 closed 8 years ago

VikR0001 commented 8 years ago

I have the following code in server/publications/collectionname.js:

import {collectionname} from '/lib/collections';
import {Meteor} from 'meteor/meteor';
import {check} from 'meteor/check';

export default function () {
  Meteor.publish('collectionname.list', function () {
    const selector = {};
    const options = {
      fields: {_id: 1, specialty: 1},
      sort: {createdAt: -1},
      limit: 10
    };

    return collectionname.find(selector, options);
  });

  Meteor.publish('collectionname.single', function (postId) { //<==A BREAKPOINT IS SET HERE
    check(postId, String);
    const selector = {_id: postId};
    return collectionname.find(selector);
  });

}

I have a breakpoint at "Meteor.publish('collectionname.single',..." Program execution does not halt at it. However, when I place a breakpoint at the same place in mantra-sample-blog-app-master, execution does halt.

It appears that the code in my app at "server/publications/collectionname.js" is not being called/executed.

In server/publications/index I have:

import collectionname from './collectionname';

export default function () {
    collectionname();
}

In lib/collections I have:

import {Mongo} from 'meteor/mongo';

export const collectionname = new Mongo.Collection('collectionname');

What needs to be done elsewhere in the code to make sure that the code in "server/publications/collectionname.js" is executed?

VikR0001 commented 8 years ago

Arunoda has kindly noted that some how-to's are needed. I've coded tons of jQuery. I've built a Meteor 1.2 test app that publishes and subscribes and does some cool stuff. But I've been hammering on publish/subscribe in Mantra for a week or so and gotten nowhere. I have tried adapting multiple Meteor Mantra sample apps and adding a new collection, but the references to collections refer back and forth to so many different files in Mantra that to a Mantra newbie like me it seems like incomprehensible spaghetti.

Could someone please post a step-by-step walkthrough describing how to add a new collection and display a list of its items in a component?

fermuch commented 8 years ago

silly question, but are you calling /server/publications/index.js from /server/index.js (or main.js, I think, is what the mantra cli tool makes) ?

For example:

import configs from './configs';
import publications from './publications';

configs();
publications();
adamdawkins commented 8 years ago

Yea, I think Fernando's onto something here. Using the mantra-cli has helped me avoid a lot of these gotchas that are a part of it being so modular. That imports publications into server/main.js for you.

On Tue, 22 Mar 2016 at 13:55 Fernando Mumbach notifications@github.com wrote:

silly question, but are you calling /server/publications/index.js from /server/index.js (or main.js, I think, is what the mantra cli tool makes) ?

For example:

import configs from './configs'; import publications from './publications';

configs(); publications();

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/kadirahq/mantra/issues/159#issuecomment-199826545

VikR0001 commented 8 years ago

Thanks very much for directing my attention to main.js. For some reason I had commented out two key lines in that file:

import publications from './publications';
import methods from './methods';

//publications();
//methods();

I have uncommented them and I'm going to see if that gets my collection to load.

Also, thanks for telling me about mantra-cli. I'm going to have a look at it.

VikR0001 commented 8 years ago

I've created a starter app using Meteor CLI. I don't have Subscribe working yet, but a question about that should probably be for another post. Using the CLI appears to answer the question I asked at the top of this thread. Thanks very much for telling me about mantra-cli.