Giter Site home page Giter Site logo

Am I doing this right? about meteor-promise HOT 8 CLOSED

deanrad avatar deanrad commented on July 19, 2024
Am I doing this right?

from meteor-promise.

Comments (8)

deanrad avatar deanrad commented on July 19, 2024

It looks like you got upgraded to version 2.0, which eliminates done in the interest of being compatible with ES6 promises. You can:

  1. replace done with then or..
  2. depend on deanius:[email protected] in .meteor/packages

That should fix at least one of your errors, let me know how it goes after.

from meteor-promise.

tehfailsafe avatar tehfailsafe commented on July 19, 2024

Thanks for the info, but even without adding the done method at all I still can't get the promises to work. I think I simply don't understand where/how to create the correct functions.

In your example in the readme, you create a createCustomer function that returns a promise to createCustomer. Then you call that function with Meteor.promise("createCustomer")? Which createCustomer function is it referring to? It looks like Meteor.promise("function") should look for a Meteor.methods function, but you created a generic one with the same name then promised it?

Following the stripe example, I have two meteor methods stripeCreateCustomer and stripeCreateSubscription which uses the fibers/future stuff. How should I lay out my Meteor.promise to first call stripeCreateCustomer and then stripeCreateSubsription?

Why is the promise method in quotes but the then method not, but you create both as functions in the same context?

from meteor-promise.

deanrad avatar deanrad commented on July 19, 2024

I completely updated the README, correcting errors and simplifying.

Particularly I went to the style where the functions inside of then are unnamed. Declaring functions to use as promise steps, prior to using them is an optional, advanced thing. I see the confusion it was causing, as they were named similar to the ones on the server, yet doing slightly different things.

Also, in your case I want to point out that you don't typically want to use Promises on the server, in the Meteor.methods call, you use them only in the browser to sequence and error-handle the Meteor.call that you make.

Does that clear it up now ?

from meteor-promise.

tehfailsafe avatar tehfailsafe commented on July 19, 2024

I ended up dumping most of the meteor chef's code. It was simply too confusing for me to follow, he was calling a server method that then called two more server methods, which used futures. Combining all the futures + promises + callbacks was too confusing for my simple brain.

Also the stripe API changed and you can now create the customer and subscription at the same time.

I ended up with this, seems like I got it right based on your last update!

client/userProfile.js

createSubscription(){
    Stripe.setPublishableKey("KEY")

    // update to real content, just using placeholder CC number for now
    Stripe.card.createToken({
      number: "4242424242424242",
      cvc: "123",
      exp_month: "12",
      exp_year: "17",
    }, (status, response) => {
      stripeToken = response.id;

      Meteor.promise("createSubscription", stripeToken, this.user)
        .then( (customer) => {
          return Meteor.promise("updateUser", customer, this.user)
        })
        .done( () => {
          console.log("done?");
        })
    });
  },

from meteor-promise.

deanrad avatar deanrad commented on July 19, 2024

Nice. And ES6 too :)

from meteor-promise.

tehfailsafe avatar tehfailsafe commented on July 19, 2024

Actually, I am now getting a new error: Uncaught TypeError: undefined is not a function which points to my catch function:

Meteor.promise("createSubscription", stripeToken, this.props.user)
        .then( (customer) => {
          return Meteor.promise("updateUser", customer, this.props.user)
        })
        .then( () => {
          console.log("done i think");
        })
        .catch( (error) => {
          console.log("error! : ", error);
        })
    });

Do you see anything glaringly obvious? I am trying to trigger the error state by signing up a customer for a plan that doesn't exist, but instead it goes through and throws that error.

from meteor-promise.

deanrad avatar deanrad commented on July 19, 2024

I don't see anything - if you look at the tests: https://github.com/chicagogrooves/deanius-meteor-promise/blob/master/tests/chaining-tests.next.js , they should show some passing examples with catch.

You can run them locally by cloning this repo, and doing meteor test-packages ./ then browsing to the address it shows.. It might be easier to try some examples outside of the stripe environment, just a thought.

from meteor-promise.

deanrad avatar deanrad commented on July 19, 2024

If you think you found a bug, reopen this and let's look at a PR with a failing test case (it's really simple).

from meteor-promise.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.