本文整理汇总了TypeScript中meteor/meteor.Meteor.subscribe方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Meteor.subscribe方法的具体用法?TypeScript Meteor.subscribe怎么用?TypeScript Meteor.subscribe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类meteor/meteor.Meteor
的用法示例。
在下文中一共展示了Meteor.subscribe方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: ngOnInit
ngOnInit() {
Meteor.subscribe('posts', () => {
this.posts = Posts.find({}, {
sort: {
dateTime: -1
}
});
});
Meteor.subscribe('timelines', () => {
this.timelines = TimeLines.find({}, {
sort: {
dateTime: -1
}
});
});
}
示例2: onReady
return this._promise((resolve, reject) => {
const handle = Meteor.subscribe(name, ...args, {
onReady() {
resolve(handle);
},
onStop(error) {
reject(error);
}
});
});
示例3: composeFn
function composeFn(_, onData) {
const subs = [
Meteor.subscribe('users.me'),
Meteor.subscribe('posts.recent')
];
if (subs.some((sub) => !sub.ready())) {
return;
}
const user = Meteor.users.findOne(Meteor.userId());
const posts = Posts.find({ author: Meteor.userId() }, {
sort: {
created_at: -1
}
}).fetch();
onData(null, { posts, user, isLoggedIn: !!user });
}
示例4:
return Observable.create(obs => {
Meteor.subscribe('userData', () => {
let user = Meteor.user();
if(!user){
this.router.navigate(['/login'])
}else{
obs.next(true);
obs.complete();
}
});
});
示例5: if
Tracker.autorun(() => {
let user = Meteor.user();
if(user){
Meteor.subscribe('teams', task._id, () => {
let team = Teams.findOne({taskId: task._id, members: user._id});
let guardingTeams = route.url.length == 3 && route.url[route.url.length-1].path == 'teams';
this.ngZone.run(() => {
if(!team && !guardingTeams){
this.router.navigate(['/tasks', task._id, 'teams'])
}else if(team && guardingTeams){
this.router.navigate(['/tasks', task._id])
}else{
obs.next(true);
obs.complete();
}
});
});
}
});
示例6:
Tracker.autorun(function () {
Meteor.subscribe("chat-history", { room: Session.get("currentRoomId") });
});
示例7: function
Tracker.autorun(function () {
Meteor.subscribe("counts-by-room", Session.get("roomId"));
});
// Checking status
let status: DDP.Status = 'connected';
console.log("Current room has " +
Counts.find(Session.get("roomId")).count +
" messages.");
/**
* From Publish and Subscribe, Meteor.subscribe section
*/
Meteor.subscribe("allplayers");
/**
* Also from Meteor.subscribe section
*/
Tracker.autorun(function () {
Meteor.subscribe("chat", { room: Session.get("current-room") });
Meteor.subscribe("privateMessages");
});
/**
* From Methods, Meteor.methods section
*/
Meteor.methods({
foo: function (arg1: string, arg2: number[]) {
check(arg1, String);
示例8: constructor
constructor() {
// Email has already been taken
// By default, Meteor only publishes the logged in user and you can, as you mention, run queries against that user.
// In order to access the other users you have to publish them on the server:
Meteor.subscribe("users.all");
}