Giter Club home page Giter Club logo

Comments (9)

Nickersoft avatar Nickersoft commented on May 18, 2024

You say for the first invocation... upon calling it in future requests, is it not undefined?

from push.js.

venkatramachandran avatar venkatramachandran commented on May 18, 2024

That is correct.

from push.js.

venkatramachandran avatar venkatramachandran commented on May 18, 2024
/* Request permission if it isn't granted */
            if (!self.Permission.has()) {
                self.Permission.request(function () {
                    return create_callback(title, options);
                });
            } else {
                return create_callback(title, options);
            }

When the flow has to request the permission, the return value is undefined to the caller.

from push.js.

sarbbottam avatar sarbbottam commented on May 18, 2024

I guess it would better to promisify and return a promise ...

from push.js.

Nickersoft avatar Nickersoft commented on May 18, 2024

@venkatramachandran Oh I see what you mean... guess that was an oversight. I can just change the scope of that return and it should work just fine, unless @sarbbottam, is there any definitive advantage to using a promise? I'm not too familiar with them. Could you elaborate?

from push.js.

sarbbottam avatar sarbbottam commented on May 18, 2024
if (!self.Permission.has()) {
    // self.Permission.request() is a async operation
    // whenever self.Permission.request() is invoked
    // self.create will return undefined
    // for sure you don't want to make self.Permission.request() synchronous
    // so, if you like to return a handle to the user 
    // I guess you have to use promise 
    self.Permission.request(function () {
        return create_callback(title, options);
    });
} else {
    return create_callback(title, options);
}

It would be something like.

// self.create is a Promise
return new Promise(function(resolve) {
    ...
    if (!self.Permission.has()) {
        // self.Permission.request is a promise
        retrurn self.Permission.request()
      .then(function() {
            // create_callback is also a promise 
            return create_callback(title, options);
        })
    } else {
        // create_callback is a promise
        return create_callback(title, options);
    }
    ...
}

from push.js.

Nickersoft avatar Nickersoft commented on May 18, 2024

@sarbbottam I see what you're saying... in fact, when I posted earlier I overlooked the fact that that call is in-fact asynchronous and so doing some research I think promises would be appropriate. However, what is the browser compatibility like for this? According to caniuse.com, IE doesn't support promises at all. Is that a kind of shim framework that could be used for older browsers?

from push.js.

sarbbottam avatar sarbbottam commented on May 18, 2024

According to caniuse.com, IE doesn't support promises at all.

IE doesn't support notifications either, I guess, it should be OK, for this use case. But its supported in Edge

Is that a kind of shim framework that could be used for older browsers?

babel-polyfill could be used, but as stated I guess, it is not required.

from push.js.

Nickersoft avatar Nickersoft commented on May 18, 2024

Wound up using the tiny 4kb library promise-polyfill to fix this, as seen in PR #32. Closing issue.

from push.js.

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.