Is there a way to avoid using createContainer?


#21

Is it possible to start using Appollo now? If so, how to install?


#22

BTW, I’ve switched to a cleaner way to handle Meteor methods in React, and passing them from a container into a child component:

Container:

import { someMeteorMethod } from '/imports/somewhere/methods';
import { promisizeMethod } from '/imports/helpers';

export default createContainer(() => {
  return {
    someMeteorMethod: promisizeMethod(someMeteorMethod),
  }
}, ChildComponent)

Where promisizeMethod is:

function promisizeMethod(method) {
  return (...args) => {
    return new Promise((resolve, reject) => {
      method.call(...args, (error, result) => {
        if (!error) resolve(result);
        else reject(error);
      });
    });
  }
}

And then inside the child component, I can call the method like so:

this.props.someMeteorMethod({
  arg1: 'Hello',
  arg2: 'World',
}).then(() => {
  /* success */
}, (error) => {
  /* error */
});

#23

Just a note - if you’re not actually interacting with a library that requires promises, making a method into a promise makes it less powerful, for example you can’t access the onResultReceived callback: http://docs.meteor.com/api/methods.html#Meteor-apply


#24

Interesting, never even knew about that option. I’m having trouble seeing a situation where I’d use it. I just switched to promises to cut back on creating a bunch of wrapper functions:

const myMethod = (args, callback) => {
  _myMethod.call(args, callback); // the original Meteor method

Because you can’t actually pass just the call method from the container:

return {
  myMethod: _myMethod.call,
}

Of course I could just pass the whole method over, and the child component could call this.props.myMethod.call(...), but I like to keep my child components 100% pure (no Meteor references).