curtislarson / meteor-waitonserver Goto Github PK
View Code? Open in Web Editor NEWSample app that shows how to use iron:router waitOn with Meteor.call
Sample app that shows how to use iron:router waitOn with Meteor.call
Hi again @quackware,
New version works well but I have a suggestion and I'm glad to know your opinion.
I guess it's better to store and retrieve data based on method name and input parameters because often many method calls with same input have a same result and this is better to getResponse from client (cache result for repetitive method call) and don't call server method again. It's also possible to add new parameter to waitOnServer for it's situation.
For example like below for force re call server method and clear data after we retrieve it with getResponse:
Util.waitOnServer("postByTitle", this.title(), this.language(), this.id(), { forceReCallServerMethod: true });
And like below for prevent new call and retrieve previous result from d_waitOns array in getResponse (if it's available) and prevent clear result for future call:
Util.waitOnServer("postByTitle", this.title(), this.language(), this.id(), { forceReCallServerMethod: false });
And like this for getResponse:
var data = this.d_waitOns[name + args].data;
var forceReCallServerMethod = this.d_waitOns[name + args].forceReCallServerMethod;
if (forceReCallServerMethod) {
this.d_waitOns[name + args] = {};
return data;
}
else {
return data;
}
Hi,
When I used ms-seo package I got bellow exception on client (firebug):
Exception in delivering result of invoking 'mymethod': Util.waitOnServer/callback@http://localhost:3000/client/utils.js?92b62c7658f435f94a973fdd2c4b275196768eb5:28:9
This is my code:
HomeController = RouteController.extend({
action: function () {
this.render('home', {
data: {
result: Util.getResponse("myMethod")
}
});
},
waitOn: function () {
return Util.waitOnServer("myMethod");
},
onAfterAction: function() {
if (!Meteor.isClient) {
return;
}
console.log(JSON.stringify(SEO));
SEO.set({
title: "Sitename - Home",
meta: {
'description': "My Description HERE",
},
og: {
'title': "Sitename - Home",
'description': "My Description HERE"
}
});
}
});
Hi again @quackware ,
I found a small bug in multiple arguments mode.
If client call a server method many times with different argument getResponse always return first call result. I think this is because of getResponse function. Because this is always get result based on server method name.
For example:
Router.route('/post/:title', { name: "postByTitle" });
PostByTitleController = RouteController.extend({
title: function(){
var title = this.params.title;
return title;
},
action: function () {
this.render('postByTitle', {
data: {
listHtml: Util.getResponse("postByTitle")
}
});
},
waitOn: function () {
return Util.waitOnServer("postByTitle", this.title());
}
});
With this route if you fist go to /post/title_1 and then go to /post/title_2 route always render title_1 post content.
What's your idea?
Hi, it's a possible execute callback.
Something like the following code.
waitOn: function () {
var router;
router = this;
return [
Util.waitOnServer('campaign.load', this.campaignSlug(), function (campaignData) {
return router.wait(Meteor.subscribe('CampaignTransactions', campaignData.id));
}),
];
}
Hi, First thanks for your awesome tutorial and guideline for meteor method with wait but I have a small question:
How to modify your util.js to accept input argument for method??
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.