This is what we am trying to achieve, we need to call an API every five min and refresh a page in meteor and we do not wish to use MongoDB; so the API call is directly made before the template renders and the output is displayed.
Below is the code snippet - I am calling the API every 5 min and setting it in session variable during the template rendering
Template.list.rendered = function(){
Meteor.setInterval(function(){
Meteor.call('getListFromAPI', function(error,data){
if(error){
console.log(error);
}
else{
Session.set('availableList', data);
}
});
}, 60000);
}
Here is the helper function which returns "availableList" to HTML for rendering -
Template.list.helpers({
'getList': function(){
return Session.get('availableList');
}
});
Problem: It works as is meaning the page refreshes every FIVE min but the problem is when the first time the page loads, it waits for five min before the rendering.
I am fairly new to Meteor, is there any other better way I tried to move the session variable to server but session is not supported in server side. I can understand that the reactive source "session - availableList" should be moved from rendered function but I am not sure what approach to use.
Please let me know if you have any question.