Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meteor methods not being called #74

Closed
derekkite opened this issue Jan 25, 2016 · 1 comment
Closed

Meteor methods not being called #74

derekkite opened this issue Jan 25, 2016 · 1 comment

Comments

@derekkite
Copy link

I have a Meteor method that calls a server function. Angular2, typescript. The method is called from the client. The logic is to insert an uploaded text file into a collection, then call a server method to process things. I do an asynchronous insert, and the Meteor.call in the callback. It works up till there, the document exists in the collection, but the method isn't called on the server.

For collections to work the ts files exporting the collection instance needs to be imported by both the server/main.ts, as well as client/app.ts. It seems that Meteor methods are the same. If the Meteor.method definition is in server/... the call doesn't work. But if I move it to collections/methods, import the files into main and app.ts, the calls to functions defined under server/ cause compiler errors.I think it is the client side compile which can't see the server/ functions.

So what is the suggested strategy? Would wrapping the import {} from calls in isServer as well as the calls themselves work? Is there a compile time flag? Or chaining Meteor method calls?

In th parties example Email is called which is in the Meteor namespace hence doesn't need to be injected. I think that is why.

Thanks.

@barbatus
Copy link
Collaborator

The strategy is to split a method into two parts: common and server ones.
Then define two methods: one simplified for the client and one full for the server;
after that import them accordingly where they belong in.
This is the only way to make it with SystemJS since direct System.import is async anyways, with CommonJS though you can import conditionally using require(...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants