Monday 15 February 2010

blocking - Block meteor helper from returning when doing http request -


I need to prevent my meteor accessory coming back immediately unless my Meteor.http .get (url) , ...) for example,

  Meteor.templateName.helpers ({testHelper: function () {var ss = "does not wait"; Meteor.http. Get ("http://api.somesite.com", function (error, result) {if (error!) {If (result.statusCode === 200) {var respJson = JSON.parse (result.content); Console.log (respJson); ss = "this value should be";}}}); return s;}}}   

is Meteor.http not blocked Call, how can I stop the subsidiary until I Do I need to receive a request for Metayr the data does not come back to get Urod. Method?

On the customer, T has a fiber module, because the result is to make a synchronous call in a function Impossible. This is a response because due to its response a session can be used, you just set a default value, and use it in your assistive function

  session .setDefault ('testHelper ', {Msg:' wait '}) Meteor.templateName.helpers ({testHelper: function () {session Sget.get (' testHelper ');}});   

Then update this session every time you want:

  Template.templateName.rendered = function () {Meteor.http.get ( "Http: /api.somesite.com", function (error, result) {if (error and result.statusCode === 200) {var respJson = JSON.parse (result.content); session.set ('TestHelper', RespJson)}}); }   

If you do not want to use session , you can use your Depps module to respond to your own responsiveness can be applied. For example, in the Meteor.http.get callback, you can set a Template.templateName attribute and invalidate a reference object to run the assist function again. Are there. But a session is definitely easier; -)

No comments:

Post a Comment