MeteorJS中的存根方法是什么? [英] What is a stub method in MeteorJS?

查看:96
本文介绍了MeteorJS中的存根方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MeteorJS中的存根方法是什么?

What is a stub method in MeteorJS?

为什么包含数据库调用会使其成为非存根?谢谢!

Why does including a database call make it a non-stub? Thanks!

推荐答案

我认为你的意思是文档?存根是通过 Meteor.methods 定义的存根。

I think you mean the ones referred to in the docs? The stubs are the ones defined via Meteor.methods.

在Meteor中,这些存根允许您进行延迟补偿。这意味着当您使用 Meteor.call 调用其中一个存根时,服务器可能需要一些时间来回复存根的返回值。当您在客户端上定义存根时,它允许您在客户端执行某些操作,以便模拟延迟补偿。

In Meteor these stubs allow you to have latency compensation. This means that when you call one of these stubs with Meteor.call it might take some time for the server to reply with the return value of the stub. When you define a stub on the client it allows you to do something on the client side that lets you simulate the latency compensation.

即我可以

var MyCollection = new Meteor.collection("mycoll")
if(Meteor.isClient) {
    Meteor.methods({
        test:function() {
            console.log(this.isSimulation) //Will be true
            MyCollection.insert({test:true});
        }
    });
}

if(Meteor.isServer) {
    Meteor.methods({
        test:function() {
            MyCollection.insert({test:true});
        }
    });
}

因此,文档将同时插入客户端和服务器上。即使服务器没有回复是否已经插入,客户端上的那个将立即反映出来。

So documents will be inserted on both the client and the server. The one on the client will be reflected 'instantly' even though the server has not replied with whether it has been inserted or not.

客户端存根允许这种情况发生没有插入两个文件,即使插入运行两次。

The client side stub allows this to happen without having two documents inserted even though insert is run twice.

如果插入失败,服务器端获胜,服务器响应客户端后,将自动删除。

If the insert fails, the server side one wins, and after the server responds the client side one will be removed automatically.

这篇关于MeteorJS中的存根方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆