Giter Site home page Giter Site logo

meteor-promise's Introduction

deanius:promise

Build Status ES 2015 Version Info Codacy Badge twitter link

Install

meteor add deanius:promise

API

The deanius:promise package gives you the following functionality:

  • Meteor.callPromise - The same as Meteor.call, but you omit the callback parameter, and it returns a Promise for the result
  • Meteor.runAsync - Uses the co NPM Library to run a JavaScript generator function yielding promises, as though it were synchronous
  • HTTP.getPromise - All methods on the HTTP object will have Promise-returning versions, just append Promise onto the method name.
  • Meteor.subscribe - The object returned by Meteor.subscribe will have a readyPromise() function which, when called, returns a Promise that resolves when ready() returns true.
  • Meteor.wrapPromise - Takes any callback-style function, and returns a Promise-returning function. This is like Meteor.wrapAsync, but useful on the client.
  • ReactivePromise - A function to wrap Promise-returning functions with, to create reactive functions - such as helpers - which update when their promised value becomes available.

Thoughts? Questions? Open an issue in deanius:promise, and let's discuss. Or find me on social media. Thanks for your interest!

meteor-promise's People

Contributors

arrygoo avatar deanius avatar deanrad avatar manueltimita avatar storytellercz avatar syzer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

meteor-promise's Issues

after upgrade to meteor 1.0.5 and promise 2.0.1 app seems to break at .done

hi,

with the previous meteor and promise 1.0.2 app was working fine

any idea where to look for the issue?

Exception in template helper: TypeError: undefined is not a function
    at Object.Template.map.helpers.aroundMe (http://localhost:3000/client/map.js?7f597dfa16c11bdf0bd700eb491b6e3d0b5402e1:158:10)
    at bindDataContext (http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:2786:16)
    at Blaze._wrapCatchingExceptions (http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:1607:16)
    at http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:2834:66
    at Function.Template._withTemplateInstanceFunc (http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:3382:12)
    at wrapHelper (http://localhost:3000/packages/blaze.js?4e49999979a58da0e2265f7bd3f5910f9901b07b:2833:27)
    at Spacebars.call (http://localhost:3000/packages/spacebars.js?7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:172:18)
    at Spacebars.mustacheImpl (http://localhost:3000/packages/spacebars.js?7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:109:25)
    at Object.Spacebars.mustache (http://localhost:3000/packages/spacebars.js?7bafbe05ec09b6bbb6a3b276537e4995ab298a2f:113:39)
    at null._render (http://localhost:3000/client/template.hvg.js?4a5bfceb447b1d5ae38a17224736e41b171cf85f:33:22)

map.js 158:10 is the line of .done ()

thanks a lot,

tinto

Provide HTTP.callPromise on the server?

I was wondering if you'd consider providing HTTP.callPromise on the server so its possible to use the same code on the client and the server without re-writing it. We often move bits of code between each and we're therefore trying to write code that runs in each.

cosmos:browserify dependency

This package adds a dependency on cosmos:browserify, which I assume is unnecessary (maybe even detrimental?) after Meteor 1.3. Should it be removed?

Am I doing this right?

Looks like I'm not sure how to follow your example, I get errors like TypeError: Object #<Promise> has no method 'done' and [TypeError: Object #<Object> has no method 'then'] while trying to arrange things properly.

Following along the meteor chef example for Stripe integration, here's my failing code:

Meteor.methods({
  createSubscription: function(customer) {
    var user = Meteor.users.findOne({_id: customer.userId});

    var getCustomer = function(customer){
      return Meteor.promise("stripeCreateCustomer", customer);
    };

    var getSubscription = function(stripeCustomer){
      return Meteor.promise("stripeCreateSubscription", stripeCustomer.id, customer.plan)
    };


    Meteor.promise("getCustomer")
          .then(getSubscription)
          .catch(function(err){
            console.log(err);
          })
          .done(function(customer){
            console.log("promise complete ", customer);
          })
  }
});

Could you give some advice? Am I supposed to put the promises in the client view template instead?

How to Synchronous call on the Server (return result)?

How to Synchronous call in server side (return result)

// Method
Meteor.methods({
   demo({name}){
      return name
  }
})

-------
// Server call
const inServer = Meteor.callPromise('demo', { name: 'Theara' })
console.log('Result', inServer) // Don't work

Problem with "loanding" text, when get data from collection on Meteor.methods()?

It don't show loading... alert:

// Server
Meteor.methods({
   getData: function(){
       var data = MyCollection.find(); // 10000 docs
       return data;
   }
})

// Client
<template name="myTpl">
  // each data
</template>

Template.myTpl.helpers({
   data: ReactivePromise(function(){
      var data = Meteor.promise('getData');
      return data;
   }, 'loading...');
})

Please help me.

Feature request: Support Meteor.subscribe

Hi! Great package.

I'd like to be able to use this for subscriptions as well:

Meteor.subscibePromise("myData").then(function () {
  // Now I have my data!
});

Basically, it should track the ready() handle on the subscription, and fire the promise when the subscription is ready.

Chaining server side

Hi @chicagogrooves , idea is nice but it doesnt work server side because of Meteor.bindEnvironment.
Lets try your example server side :

Meteor.promise("createCustomer", "[email protected]", "VISA")
  .then(Meteor.bindEnvironment(function(customer) {
    return Meteor.promise("createCustomerSubscription", customer.id, plan);
  }))
  .then(Meteor.bindEnvironment(function(plan) {
    console.log("Plan", plan);
  }))
  .catch(Meteor.bindEnvironment(function (err) {
    console.error(err);
  })) 

what we can see ? in third promise plan is undefined , it is called before any output from createCustomerSubscription.

after upgrade to meteor 1.0.5 and promise 2.0.1 there's no return value from .then(myFunc())

hi,

after the upgrade there's no return value from the promise function: .then(myFunc())

...
      Meteor.promise ("...", ...)
        .then (myFunc ())
        .done (function () {..})
        .fail (function (err) {console.error ("Bad", err);})
...

function myFunc (myParam) {
       myParam comes as undefined
       ...
}

myParam is 'undefined' whereas the promise method should return it

I can see that the method is called and there's the value which is to be received back, this worked before nicely

it worked before the upgrade, I couldn't figure out based on the release notes what was the change which resulted in my issue

what do you think what do problem could be?

thanks a lot

publish latest?

I notice there's some compatibility improvements in master that aren't published as a package. Can you publish the latest update? Thanks!

Test

  1. Acceptance tests are outlined [1]
    1. Ticket acceptance criteria correspond to automated tests steps
    2. CSS selectors for relevant elements
    3. Tests appear in the output of npm run test:acceptance
  2. Errors
    1. Sync error results are handled
    2. Async error results are checked (y, if using Promises w/ catch )
    3. Severity levels are as appropriate (w/ routing to approp. channel)
  3. Unit tests
    1. Are included as appropriate: ___________
    2. Whats another edge case you could test for? ____________
  4. Dependencies
    1. New dependencies are unpinned, or pinned with a reason
    2. Considered the tradeoff of inlining vs. depending: ________
    3. Alternatives at the time of its addition: _________
  5. Coding style
    1. Are we experiencing friction with any linting rule? ________
    2. Is it idiomatic ES6: __________
    3. Promises used consistently throughout?
    4. Is it idiomatic Meteor: __________
    5. Does it introduce/remove dead code?
    6. Does it violate the rule of 3?
  6. Localization
    1. Does it introduce unlocalized text?
  7. Tracking Status
    1. Has the ticket been moved in JIRA?

Replacing to okgrow:promise should we update our current promisses?

Hi, I wonder if we should update the syntax of the promises, once we replace to the okgrow:promise package can any promise broke? I ask this since I have more than +300 promises in my app it is pretty big so Im afraid to update to the new package and broke my current promises that are working ok.

.finally block doesn't seem to work.

Looked at the compiled result and saw 'es6-promises'. Checked out es6-promises which is a subset of rsvp. I checked out those docs and noticed there is a finally callback, which is what I was looking for, but it doesn't seem to work.

IonLoading.show();
Meteor.promise('createOrder', orderId, address)
.then(function (order) {
  return Meteor.promise('createShipment', order)
})
.then(function (shipment) {
  return Meteor.promise('chargeOrder', shipment)
})
.then(function () {
  Router.go(nextRoute);
});
.catch(function (err) {
  Orders.unset(orderId, {
    shipment: "",
    address: ""
  });
  sAlert.error("Failed to create and charge order");
})
.finally(function () {
  IonLoading.hide();
});

The traceback is like so:

Meteor.promise(...).then(...).then(...).then(...).catch(...).finally is not a function

plans to support React?

Hi, I'm wondering if there will be any plans to support promises on React. I'm thinking in something like this:

Session.set 'arg1', 1
Session.set 'arg2', 2

@Main = React.createClass
    mixins : [ReactMeteorData]
    getMeteorData: ->
        data = {}
        arg1 = Session.get 'arg1'
        arg2 = Session.get 'arg2'
        data.promise = Meteor.call('add', arg1, arg2)
        data
    render: ->
        <div>
            hello: {@data.promise}
        </div>

Thanks.

Getting "TypeError: Object [object Object] has no method 'callPromise'"

I'm a bit confused (NB this is my first Meteor project, so I may be totally out to lunch on this...)

  • I want to write an app that calls a server-side library that uses Promises.
  • I used meteor add deanius:promises and see deanius:promise in .meteor/packages
  • I have a (stub) server-side method defined like this:
function kcommand(cmd) {
    return new Promise( function(resolve,reject){
        resolve("Cmd was %{cmd}");  // just a stub for a functioning method
    });
  • I call it with a main() like this:
foo = Meteor.callPromise('kcommand', 'kVersion');
  • As noted, I see a "TypeError: Object [object Object] has no method 'callPromise'" message at the point it calls Meteor.callPromise()
  1. What should I do to make Meteor.callPromise work?
  2. Do I have to require() anything in my source files?
  3. Should I be using deanius:promise in a new project? Is there a fully-supported Meteor package for working with promises?

Many thanks.

Getting errors running tests in Meteor 1.3-rc.2

Just upgraded from 1.3-beta.12 to 1.3-rc.2 and now I get the following error

 While processing files with cosmos:browserify (for target web.browser):
   packages/deanius:promise/client/runAsync.browserify.js: Cannot read
   property '0' of undefined

EDIT: The error is present outside of testing as well.

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.