13 ms·
Allora – Use promises on any JavaScript object
- pythonistah 10y agoIt uses Proxy and Promise classes.
- izym 10y agoThe point is to take APIs that don't and wrap them with said classes, not to provide an alternative.
- pythonistah 10y agoWhat percentage of browsers in use implement Proxy and Promise classes? 40 percent?
- JonathonW 10y agoPer Can I Use [1], promises are in 74% of browsers (only current major browser not supporting them is IE11) and proxies are in 57% of browsers. Promise is pretty easily polyfilled for older browsers; proxies are more problematic and I don't know whether or not any of the existing proxy polyfills will work with Allora. [1] http://caniuse.com/ http://caniuse.com/
- pythonistah 10y agoThe data behind their world wide browser stats is questionable. - their combined IE and Edge market share totals to only 8%. On https://www.netmarketshare.com https://www.netmarketshare.com combined IE market share is 31% and Edge is 5%.
- nilliams 10y agoWhat about IE8-10? I agree with pythonistah, that can-i-use data doesn't really map to real-world usage.
- pythonistah 10y agoPerhaps they only collect data from browsers hitting their web site?
- gianlucaguarini 10y agoyou got it, there are many libraries on npm doing the same but none was build with less than 50 lines of code
- ilaksh 10y agoCool but what was wrong with all of the other modules that do this? There are like 30 of them. https://npms.io/search?term=Promisify https://npms.io/search?term=Promisify
- gianlucaguarini 10y agothe amount of code and the technology used ;)
- jagger27 10y agoI love the name.
- deleted 10y ago[deleted]
- c-smile 10y agoIt is not possible to fulfill promise more than once. Thus promisifying of window.setInterval() and window.requestAnimationFrame() is very questionable. The same applies to possibly repeatable .onXXXX() methods. 2.2.2 If onFulfilled is a function: ... 2.2.2.3 it must not be called more than once. https://promisesaplus.com/ https://promisesaplus.com/
- foota 10y agorequestAnimationFrame doesn't repeat, it only triggers the function once, you have to request an animation frame on each render to have it run again. Valid point however regarding the other things. Might be a neat api to have like a generator for these kinds of things, something like: for click in window.document.body: // do something with click and then stick this in an async function?
- gianlucaguarini 10y agoSee my answer above :)
- throwanem 10y agoIt's not possible to fulfill a promise more than once, no. But a Promise.all method, while outside the A+ spec, conventionally returns a promise for the resolution of all promises in the array passed as an argument; if all those promises are fulfilled, so will be the promise returned by .all, while if any of them is rejected, so will be the etc., etc. So the browser example given in the Allora Github readme is perfectly reasonable. It's the exact same kind of thing you do when, for example, you need to await the completion of multiple separate HTTP requests in order to do something with all of their results. While, again, .all isn't part of the A+ standard, this is perfectly conventional and unremarkable behavior; not only is it unsurprising to see in a library like this one, it would be exceptional in its absence if it weren't there. That said, I would be curious to see Allora compared with, for example, Bluebird's "promisifyAll" method, which appears to do much the same thing.
- c-smile 10y ago
- k__ 10y agoIs there an equivalent for RxJS?
- nippur72 10y agonice small lib as you'd expect from @gianlucaguarini (of Riot.js fame). Also, it's async/await ready: const allora = require('allora') const myGlobal = allora(global) async function foo() { console.log("start") await myGlobal.setTimeout(2000) console.log("end") } foo()