Meteor How to export Meteor.publish and Meteor.method code from within a Meteor package

為{幸葍}努か 提交于 2019-12-24 00:47:24

问题


Here is a package.js file

Package.describe({
  summary: 'Client Collection Paging Class designed for use with Meteor'
});

Package.on_use(function (api) {
    api.use( 'underscore', [ 'client', 'server' ] ) ;
    api.use( 'ejson', [ 'client', 'server' ] ) ;
    api.add_files( 'lib/pageMan.js',  'client' ) ;
    //api.add_files( 'lib/pageMan_publish.js', 'server' ) ;
    //api.add_files( 'lib/pageMan_method.js', [ 'client', 'server' ] ) ;

    if ( typeof api.export !== 'undefined' ) {
        api.use( 'webapp', 'server' ) ;
        Npm.depends( { connect: '2.7.10' } ) ;
        api.export( 'Pager', 'client' ) ;
      //api.export( 'methods', [ 'client', 'server' ] ) ;   
      //api.export('publish', 'server' ) ;
        api.export( 'pagingUpdate', 'client' ) ;
        api.export( 'pagingSubscribe', 'client' ) ;
        api.export( 'pagingFirst', 'client' ) ;
        api.export( 'pagingNext', 'client' ) ;
        api.export( 'pagingPrev', 'client' ) ;
        api.export( 'pagingLast', 'client' ) ;

    } ;
      });

I have a single Meteor.methods in /lib/pageMan_method.js and a single Meteor.publish in /lib/pageMan_publish.js If the code from these two files is placed in appropriate files in an example app the app works fine. I am trying to add them to my package but when I un-comment the 4 references in the packages.js file, the Server console reports

Object #<Object> has no method 'publish'  or  Object #<Object> has no method 'method'

I did try an api.use('meteor', ['client','server'] but no joy either.

Could someone please enlighten me if...

  • Is it possible to export publications and methods from a package;
  • Can I do it correctly.

回答1:


Make sure you use the livedata packages.

api.use( 'livedata', [ 'server' ] ) ;

Typically the packages have access to a very barebones version of meteor. (With absolutely no packages).



来源:https://stackoverflow.com/questions/19986141/meteor-how-to-export-meteor-publish-and-meteor-method-code-from-within-a-meteor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!