本文整理汇总了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}
});
}
}
]
};
});
}
示例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);
});
}
示例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 } }
]
});
});
示例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 });
});
示例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
});
});
示例6:
import { Meteor } from 'meteor/meteor';
Meteor.publish('users', () => {
return Meteor.users.find({}, {
fields: {
username: 1,
profile: 1
}
});
});
示例7: function
import { Activity } from '../../../both/collections/activity.collection';
import { Meteor } from 'meteor/meteor';
Meteor.publish("activity", function() {
return Activity.find({public:true});
});
示例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
}, ],
}
);
});
示例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
示例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
}
});
});