News for hackers. Stuff that matters.
Re:Allora – Use promises on any JavaScript object by c-smile on Monday July 18, 2016 @07:21PM (#12118564)
It 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/
Re:Allora – Use promises on any JavaScript object by gianlucaguarini on Tuesday July 19, 2016 @12:55AM (#12119781)
Yes you are right, mine was just a proof of concept and it works properly for callbacks that must be triggered only once. I am working on another script to make an event streams api from native functions a bit like Bacon.js or fx.js already do but with less code
Re:Allora – Use promises on any JavaScript object by throwanem on Monday July 18, 2016 @07:44PM (#12118636)
It'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.

Re:Allora – Use promises on any JavaScript object by c-smile on Monday July 18, 2016 @08:21PM (#12118755)
So what does this

   thatWindow.setInterval(100).then( foo )
mean exactly? How many times the foo() will be called? And how to stop that interval?
Re:Allora – Use promises on any JavaScript object by gianlucaguarini on Tuesday July 19, 2016 @12:56AM (#12119791)
foo will be called only once (see my answer above). I am working on another script to achieve event streams using es6 generators let's keep in touch
Re:Allora – Use promises on any JavaScript object by egeozcan on Tuesday July 19, 2016 @07:44AM (#12121139)

    promisifiedWindow.setInterval(200).then(x => console.log("res:", x));
    -> Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined}
    >> VM310:1 res: undefined
How do you cancel the interval?
Re:Allora – Use promises on any JavaScript object by gianlucaguarini on Tuesday July 19, 2016 @08:45AM (#12121380)
Ok with this it should be possible https://github.com/GianlucaGuarini/allora/pull/3
Re:Allora – Use promises on any JavaScript object by gianlucaguarini on Tuesday July 19, 2016 @07:51AM (#12121168)
At moment it's not possible and it does not make any sense to use a setInterval with a promise in return. But I will think about a simple solution to clear the timer functions
Re:Allora – Use promises on any JavaScript object by foota on Monday July 18, 2016 @07:41PM (#12118628)
requestAnimationFrame 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?
Re:Allora – Use promises on any JavaScript object by gianlucaguarini on Tuesday July 19, 2016 @12:55AM (#12119783)
See my answer above :)
Re:Allora – Use promises on any JavaScript object by ilaksh on Monday July 18, 2016 @06:57PM (#12118491)
Cool 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
Re:Allora – Use promises on any JavaScript object by gianlucaguarini on Tuesday July 19, 2016 @12:58AM (#12119802)
the amount of code and the technology used ;)
Re:Allora – Use promises on any JavaScript object by nippur72 on Tuesday July 19, 2016 @07:48AM (#12121154)
nice 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()
Re:Allora – Use promises on any JavaScript object by jagger27 on Monday July 18, 2016 @07:18PM (#12118557)
I love the name.
Re:Allora – Use promises on any JavaScript object by k__ on Tuesday July 19, 2016 @07:25AM (#12121075)
Is there an equivalent for RxJS?
Re:Allora – Use promises on any JavaScript object by pythonistah on Monday July 18, 2016 @06:51PM (#12118477)
It uses Proxy and Promise classes.
Re:Allora – Use promises on any JavaScript object by izym on Monday July 18, 2016 @07:18PM (#12118553)
The point is to take APIs that don't and wrap them with said classes, not to provide an alternative.
Re:Allora – Use promises on any JavaScript object by pythonistah on Monday July 18, 2016 @07:37PM (#12118617)
What percentage of browsers in use implement Proxy and Promise classes? 40 percent?
Re:Allora – Use promises on any JavaScript object by JonathonW on Monday July 18, 2016 @10:49PM (#12119237)
Per 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/

Re:Allora – Use promises on any JavaScript object by pythonistah on Tuesday July 19, 2016 @12:44AM (#12119736)
The 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 combined IE market share is 31% and Edge is 5%.

Re:Allora – Use promises on any JavaScript object by nilliams on Tuesday July 19, 2016 @06:43AM (#12120950)
What about IE8-10? I agree with pythonistah, that can-i-use data doesn't really map to real-world usage.
Re:Allora – Use promises on any JavaScript object by pythonistah on Tuesday July 19, 2016 @08:59AM (#12121445)
Perhaps they only collect data from browsers hitting their web site?
Re:Allora – Use promises on any JavaScript object by gianlucaguarini on Tuesday July 19, 2016 @01:00AM (#12119804)
you got it, there are many libraries on npm doing the same but none was build with less than 50 lines of code