Giter VIP home page Giter VIP logo

Comments (12)

markmarijnissen avatar markmarijnissen commented on May 22, 2024

It needs a Promise library according to the offical Promise/A+ spec.

I'll update documentation to be more precise and give you an example. Hold on!

from cordova-app-loader.

markmarijnissen avatar markmarijnissen commented on May 22, 2024

According to the documentation of $q, angular is compatible with the ES6 specification on MDN.

Seeing the example, it does everything I need:

// for the purpose of this example let's assume that variables `$q` and `okToGreet`
// are available in the current lexical scope (they could have been injected or passed in).

function asyncGreet(name) {
  // perform some asynchronous operation, resolve or reject the promise when appropriate.
  return $q(function(resolve, reject) {
    setTimeout(function() {
      if (okToGreet(name)) {
        resolve('Hello, ' + name + '!');
      } else {
        reject('Greeting ' + name + ' is not allowed.');
      }
    }, 1000);
  });
}

var promise = asyncGreet('Robin Hood');
promise.then(function(greeting) {
  alert('Success: ' + greeting);
}, function(reason) {
  alert('Failed: ' + reason);
});

$q.all([asyncGreet('Mark'),asyncGreet('Lyle').then(function(names) { 
    console.log('We are '+names.join(' and '));
});

So you should be able to pass $q and have it work! Can you check if this is true?

from cordova-app-loader.

lylepratt avatar lylepratt commented on May 22, 2024

I tried passing $q, but it does not work.

Here is the error that occurs:
deviceready = new Promise(function(resolve,reject){ (Object is not a function)

from cordova-app-loader.

markmarijnissen avatar markmarijnissen commented on May 22, 2024

Ok, I'll check that out!

from cordova-app-loader.

markmarijnissen avatar markmarijnissen commented on May 22, 2024

Fixed (7e6e87c)! Can you confirm? (Please use file from the repo - I haven't published to NPM or Bower yet).

I was using Promise.resolve(...) in CordovaPromiseFS which isn't part of the official spec.

You can run the CordovaAppLoader demo and then point the manifest to: http://data.madebymark.nl/cordova-app-loader/issues/angular-q/manifest.json. You should see a popup with "OK" before it reverts to factory default. You can check out the angular example here.

from cordova-app-loader.

lylepratt avatar lylepratt commented on May 22, 2024

This still doesn't work just by passing $q to the Promise parameter. new $q() is not going to work (which is where it fails).

from cordova-app-loader.

markmarijnissen avatar markmarijnissen commented on May 22, 2024

Actually, the specification they claim to be following also uses new. I have tried it with this example, and it works fine. Are you sure? (Can you give me code to reproduce the error?)

from cordova-app-loader.

lylepratt avatar lylepratt commented on May 22, 2024

I've continued to try this, but passing $q to the function does not work (at least it does not in angular 1.3).

Does not work:

        // Initialize a FileSystem
        var fs = new CordovaPromiseFS({
          Promise: $q
        });

Fails with:

deviceready = new Promise(function(resolve,reject){ (Object is not a function)

from cordova-app-loader.

markmarijnissen avatar markmarijnissen commented on May 22, 2024

Are you sure you're using Angular 1.3? I know that Angular 1.2.x does not support the Promise/A+ syntax for $q.

Can you check with this manifest: http://data.madebymark.nl/cordova-app-loader/issues/angular-q/manifest.json. (Please use http://data.madebymark.nl/cordova-app-loader/ as your serverRoot).

Still have the issue then?

from cordova-app-loader.

lylepratt avatar lylepratt commented on May 22, 2024

I believe I found what was wrong and it was entirely my fault. So sorry for wasted time!

from cordova-app-loader.

markmarijnissen avatar markmarijnissen commented on May 22, 2024

No problem!

from cordova-app-loader.

yogibimbi avatar yogibimbi commented on May 22, 2024

Hi Mark, I found an error in your example code in the Readme.md, that had me stuck when trying to include. You write

var fs = CordovaPromiseFS({
persistent: true, // or false
storageSize: 20_1024_1024, // storage size in bytes, default 20MB
concurrency: 3 // how many concurrent uploads/downloads?
Promise: require('promiscuous') // Your favorite Promise/A+ library!
});

And I just c&p'd the code and was wondering why replacing require('promiscuous') with $q resulted in an error. Turns out, there is a comma missing after concurrency: 3and Chrome's feedback led me a bit astray before finding that. You might want to correct that;-) Apart from that: congrats and thanks for the library!

from cordova-app-loader.

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.