Remove server-only class methods?

Hi.

I’m wondering if anybody has a elegant way of removing certain methods from a class.

Case in point, I have my collections represented by a class each. These classes are put on both server and client. However, some methods are only used server-side, and I would like to have the meteor tool remove those to minimize the client code size (and to avoid exposing them).

I suppose I could do something along the lines of

class basePostsCollection {
    sharedMethod () {
        ...
    }
}

if (Meteor.isServer) {
    class PostsCollection extends basePostsCollection {
        serverOnlyMethod () {
            ...
        }
    }
} else {
    class PostsCollection extends basePostsCollection {

    }
}

…but what I’d rather do was something like

class PostsCollection {
    sharedMethod () {
        ...
    }

    // @server
    serverOnlyMethod () {
        ...
    }
}

…and then have the build tool remove the serverOnlyMethod based on the // @server comment.

Does anyone know of any tooling that achieves this?

Should probably add that I’m already removing Meteor.isServer blocks, or the above does not make sense :slight_smile:

1 Like