What is a stub method in MeteorJS?

后端 未结 2 418
你的背包
你的背包 2020-12-24 15:17

What is a stub method in MeteorJS?

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

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-24 16:11

    For the above code you can write this that will be ran on both server and client, use isSimulation to identify on wich side you are if you need to do specific task :

    var MyCollection = new Meteor.collection("mycoll")
    Meteor.methods({
        test:function() {
            console.log(this.isSimulation) //Will be true on client and false on server
            var colItem = {test:true, server: true};
            if (this.isSimulation) {
                colItem.server = false;
            }
            MyCollection.insert(colItem);
        }
    });
    

提交回复
热议问题