KonVas
KonVas

Reputation: 267

Meteor.methods vs. standard JS function invocation

Can I place standard JS functions and invoke them as usual as well as invoke them from (Meteor) events? I am reading about Methods in Meteor and I am not sure if is okay to write some functions just inside my isClient conditional and invoke them as normal. I have something like this, which the second function 'normalize_scale_offset' is called by a Meteor event.

function normalize(val, max=1, min=0.1) {
        return (val - min) / (max - min);
    };

    function normalize_scale_offset(input, scale=1, offset=0) {
        var normalized = input.map((val) => normalize(val, Math.max(...input), Math.min(...input)));
        return normalized.map( (val) => val * scale + Math.sqrt(offset) ).map((val) => val * 1000);
    };

Upvotes: 1

Views: 69

Answers (2)

d4nyll
d4nyll

Reputation: 12617

Generally, you'd use methods if you want to invoke something to run on the server. If you're just running things on the client, just use a normal function.

Upvotes: 0

Michel Floyd
Michel Floyd

Reputation: 20227

Yes, js functions are perfectly acceptable either on the client or on the server. Only when the client needs to invoke a function on the server is a Method required.

Upvotes: 2

Related Questions