MeteorJS: callback after adding template helper

I am new to Meteor.js so hope this is a failure on my part and not a platform limitation because it is pretty amazing.

What I am trying to achieve is quite simple: run Javascript whenever the template helper is updated with new data (but not from the db!).

A simple example scenario might be as follows: A user makes a request to get some images. But instead of the images just "popping out", they should be hidden and disappear after they are fully loaded (like their positioning, etc.).

In other words, immediately after the helper receives new data, the function must run to do something with that data (which cannot be executed on the server before it is actually displayed).

If the data is from a collection, it is fairly easy to achieve this with a subscription callback.

However, it looks like there was no callback as soon as the helper provided new data.

Yes, it is possible to add a few ms timeout, but this is not a clean or reliable solution in my opinion, because you obviously never know exactly how long it will take to render.

I've searched for dozens of seemingly related posts, but couldn't find anything that could be considered a "standard" way to achieve this ...

Here is some (simplified) sample code to illustrate the scenario:

var images = [];


//When showImages is updated with new data from the images array...
Template.gallery.helpers({

    showImages: function () {
        return images;
    }
});

//...this function should fire
function doMagicWork () {
    ...
}


//Because firing it on the on click event would be too soon,
//as the helper hasn't rendered yet
Template.gallery.events({

    "click #fetch_images": function (event) {

        Meteor.call("getImagesFromServer", function(error, result) {

            images = result.content;

        });
    }
});

      

+3


source to share


1 answer


Tracking the ability to add animation / transition support for UI changes ( link here )

You can use Blaze UI hooks as an intermediate solution. There are quite a few of them. example here and here



In general, Meteor's way is to reduce the number of the code plate. A smooth transition is something like a template, not a separate thing for an element, and should be treated as such, as in relation to meteoric philosophy.

0


source







All Articles