當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Meteor.publish方法代碼示例

本文整理匯總了TypeScript中meteor/meteor.Meteor.publish方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Meteor.publish方法的具體用法?TypeScript Meteor.publish怎麽用?TypeScript Meteor.publish使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在meteor/meteor.Meteor的用法示例。


在下文中一共展示了Meteor.publish方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: initPublications

export function initPublications() {
  Meteor.publish('users', function(): Mongo.Cursor<User> {
    if (!this.userId) return;

    return Users.collection.find({}, {
      fields: {
        profile: 1
      }
    });
  });

  Meteor.publish('messages', function(chatId: string): Mongo.Cursor<Message> {
    if (!this.userId) return;
    if (!chatId) return;

    return Messages.collection.find({chatId});
  });

  Meteor.publishComposite('chats', function() {
    if (!this.userId) return;

    return {
      find: () => {
        return Chats.collection.find({memberIds: this.userId});
      },

      children: [
        {
          find: (chat) => {
            return Messages.collection.find({chatId: chat._id}, {
              sort: {createdAt: -1},
              limit: 1
            });
          }
        },
        {
          find: (chat) => {
            return Users.collection.find({
              _id: {$in: chat.memberIds}
            }, {
              fields: {profile: 1}
            });
          }
        }
      ]
    };
  });
}
開發者ID:pro-to-tip,項目名稱:pro-to-tip.github.io,代碼行數:48,代碼來源:publications.ts

示例2: function

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

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

  Meteor.publish('posts.single', function (postId: string) {
    check(postId, String);
    const selector = {_id: postId};
    return Posts.find(selector);
  });

  Meteor.publish('posts.comments', function (postId: string) {
    check(postId, String);
    const selector = {postId};
    return Comments.find(selector);
  });
}
開發者ID:TribeMedia,項目名稱:meteor-mantra-redux-graphql,代碼行數:24,代碼來源:posts.ts

示例3: function

import {Orders} from '../collections/orders';
import {Meteor} from 'meteor/meteor';

Meteor.publish('orders', function() {
   // return Orders.find();
    return Orders.find({

                $and: [
                    { owner: this.userId },
                    { owner: { $exists: true } }
                ]
    });
});
開發者ID:ayush2016,項目名稱:meteor1.3.2.4-angular2.0-olog,代碼行數:13,代碼來源:orders.ts

示例4: function

import {Meteor} from 'meteor/meteor';
import {Users} from './../../collections/users';
import {Counts} from 'meteor/tmeasday:publish-counts';
import * as Helpers from "./../../lib/helpers";

Meteor.publish("users.all", function(options: Object) {
    Counts.publish(this, "users.total", Users.find({}), { noReady: true });
    let secure = {
        fields: {
            "emails.address": 1,
            "createdAt": 1,
            "profile": 1
        }
    }
    options = Helpers.mergeOptions(options, secure);
    return Users.find({}, options);
});

Meteor.publish("users.detail", function(id: string) {
    return Users.find({ _id: id });
});
開發者ID:euclid1990,項目名稱:fruit,代碼行數:21,代碼來源:user.component.ts

示例5: function

import {Meteor} from 'meteor/meteor';
import {GamificationGrid, GamificationRecords} from './collection';


Meteor.publish('gamification.records', function () {
    console.log('publishing records')
    return GamificationRecords.find({
        user_id: this.userId
    });
});

Meteor.publish('gamification.grid', function() {
    console.log('publishing grid')
    return GamificationGrid.find({
        user_id: this.userId
    });
});
開發者ID:kucharskimaciej,項目名稱:bullet-journal,代碼行數:17,代碼來源:publish.ts

示例6:

import { Meteor } from 'meteor/meteor';

Meteor.publish('users', () => {
  return Meteor.users.find({}, {
    fields: {
      username: 1,
      profile: 1
    }
  });
});
開發者ID:RizkiMufrizal,項目名稱:Socially-Angular2-Meteor,代碼行數:10,代碼來源:users.ts

示例7: function

import { Activity } from '../../../both/collections/activity.collection';
import { Meteor } from 'meteor/meteor';

Meteor.publish("activity", function() {
  return Activity.find({public:true});
});
開發者ID:michaelb-01,項目名稱:pipe,代碼行數:6,代碼來源:activity.ts

示例8: tasksPublication

import {Tasks} from '../collections/tasks';
import {Meteor} from 'meteor/meteor';


  Meteor.publish('tasks', function tasksPublication() {
  return Tasks.find({owner: this.userId}); // find only user tasks
});



Meteor.publish('task', function(taskId: string) {
  return Tasks.find(
    {
      $and: [{  // find with given task id
          '_id': {
            $eq: taskId
          }
        }, { // find only if the owner access the task
          'owner': this.userId
        }, ],
      }
);

});
開發者ID:LIOSK-ORG,項目名稱:todo-app,代碼行數:24,代碼來源:tasks.ts

示例9: function

import { Meteor } from 'meteor/meteor';
import { Counts } from 'meteor/tmeasday:publish-counts';

import { Poems } from '../../../both/collections/poems.collection';
import { PoemFilter } from '../../../both/filters/poem-filter';
import { Options } from '../../../both/filters/pagination';

Meteor.publish('poems', function(options: Options, filter?: PoemFilter) {
    // Publish total count
    Counts.publish(
        this,
        'numberOfPoems',
        Poems.collection.find(buildQuery.call(this, filter)),
        { noReady: true });

    // Return filtered poems
    return Poems.find(buildQuery.call(this, filter), options);
});

function buildQuery(filter?: PoemFilter): Object {
    const completeQuery = {
        // All users (even anonymous) can see completed poems
        isComplete: true
    };

    // Base query for poem permissions
    const baseQuery = this.userId
        ? { 
            $or: [completeQuery, {
                lastContributorId: {
                    // Logged in users can edit poems for which they're
開發者ID:babyshoes,項目名稱:exquisite-corpus,代碼行數:31,代碼來源:poems.ts

示例10: function

import {Parties} from '../collections/parties';
import {Meteor} from 'meteor/meteor';

Meteor.publish('uninvited', function(partyId: string) {
    let party = Parties.findOne(partyId);

    if (!party)
        throw new Meteor.Error('404', 'No such party!');

    return Meteor.users.find({
        _id: {
            $nin: party.invited || [],
            $ne: this.userId
        }
    });
});
開發者ID:RichardHwang886,項目名稱:socially16,代碼行數:16,代碼來源:users.ts


注:本文中的meteor/meteor.Meteor.publish方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。