本文整理匯總了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");
}