Re: Promise capability support

2018-07-25 Thread Michael Theriot
FWIW I have never heard of this terminology before either but in practice have used the pattern myself. On Thu, Jul 26, 2018 at 12:15 AM, Bob Myers wrote: > > It allows you to reveal things, selectively, just as the revealing > module pattern does. \ > > The revealing module pattern is so named

Re: Promise capability support

2018-07-25 Thread Bob Myers
> It allows you to reveal things, selectively, just as the revealing module pattern does. \ The revealing module pattern is so named precisely because it reveals (to clients) certain aspects of the "module" in question. Yes, it hides other aspects, but only by virtue of not revealing them. If you

Re: Promise capability support

2018-07-25 Thread Jordan Harband
It allows you to reveal things, selectively, just as the revealing module pattern does. (separately, the measure of "caught on" is not "there does not exist someone who has not heard of it") On Wed, Jul 25, 2018 at 2:04 PM, Bob Myers wrote: > Not to beat a dead horse but > > * No, it hasn't cau

Re: Promise capability support

2018-07-25 Thread Bob Myers
Not to beat a dead horse but * No, it hasn't caught on, as evidenced by the recent poster who had never heard of it. * Yes, I know it's used to describe the Promise executor pattern. * "Revealing module pattern" reveals. The so-called "revealing constructor pattern" does not reveal anything. It hi

Re: Promise capability support

2018-07-25 Thread Jordan Harband
It's already caught on - "revealing constructor pattern" is the pattern that describes the Promise executor. The "revealing module" pattern is obsolete anyways, but it functions on the same principle - using closures to reveal only explicit things instead of everything. On Wed, Jul 25, 2018 at 10

Re: Promise capability support

2018-07-25 Thread Bob Myers
Yes, I've encountered this "revealing constructor" terminology and find it confusing. I hope it doesn't catch on. A lot of people are likely to try to associate it with the "revealing module" pattern, with which it actually has nothing in common. It's a strange term because this pattern, if one wan

Re: Promise capability support

2018-07-25 Thread Isiah Meadows
Here's a quick overview of the "revealing constructor" pattern, if it helps: https://blog.domenic.me/the-revealing-constructor-pattern/ - Isiah Meadows m...@isiahmeadows.com www.isiahmeadows.com On Wed, Jul 25, 2018 at 7:05 AM, Herbert Vojčík wrote: > > > Isiah Meadows wrote on 20. 7. 2018

Re: Promise capability support

2018-07-25 Thread Herbert Vojčík
Isiah Meadows wrote on 20. 7. 2018 3:13: Sometimes, it's *very* convenient to have those `resolve`/`reject` functions as separate functions. However, when logic gets complex enough and you need to send them elsewhere, save a continuation, etc., it'd be much more convenient to just have a capab

Re: Promise capability support

2018-07-21 Thread Isiah Meadows
Fair enough. I was just hoping that the internal mechanism itself could be exposed, since the spec already has to use it (as do implementations 99% of the time). In case you're concerned about the potential for abuse, I do have this: 1. It's different than what you'd get with `new Promise(...)` it

Re: Promise capability support

2018-07-21 Thread Augusto Moura
Reject and resolve static methods are not introducing a new ~maybe dangerous~ pattern into the language, they are just isolating a factory for a common use case (creating a promise wrapping a well know value at the time of execution), deferreds add a whole lot of indirection in the table, that migh

Re: Promise capability support

2018-07-21 Thread Jordan Harband
The use cases for "i want a resolved or rejected promise for a value/reason" are much more numerous than for "i want a deferred", so yes, I don't think a Deferred belongs in the language, and I think Promise.resolve/reject absolutely clear that bar. On Sat, Jul 21, 2018 at 11:19 AM, Isiah Meadows

Re: Promise capability support

2018-07-21 Thread Isiah Meadows
> I think what Jordan means, it's that the deferred has it use case, but > probably we don't want it in Javascript native library. There's a lot of > mature libraries implementing deferred wrappers and most of them are Promise > like compatible, and even if you cannot use libraries or don't want to

Re: Promise capability support

2018-07-21 Thread Isiah Meadows
Just a heads up: that will throw, since the Promise constructor executes its callback synchronously, and thus `this` isn't set up in the callback until *after* it's called. You should probably rewrite it the callback to store them locally and then set the properties and call the factory after: ```

Re: Promise capability support

2018-07-20 Thread Augusto Moura
You are right, I didn't know you can use variables before calling the super constructor (a Java thing). So yeah, it's pretty easy to extend a Promise to externalize resolve and reject --- PS: Sorry about my last email last paragraph grammar, I'm yet getting used to write long texts in English Em

Re: Promise capability support

2018-07-20 Thread Richard Gibson
On Fri, Jul 20, 2018 at 12:15 PM Augusto Moura wrote: > Interesting enough, I got a really weird case (reads contraintuitive, I'm > pretty sure the semantics of the error are right) extending the Promise > class to exemplify a simple Deferred implementation, the code: > > ``` js > class Deferred

Re: Promise capability support

2018-07-20 Thread Augusto Moura
I think what Jordan means, it's that the deferred has it use case, but probably we don't want it in Javascript native library. There's a lot of mature libraries implementing deferred wrappers and most of them are Promise like compatible, and even if you cannot use libraries or don't want to, you ca

Re: Promise capability support

2018-07-20 Thread Michael Theriot
So I run into this issue when waiting on multiple events I don't initiate. What I do is create a subclass of promise that exposes these calls. Not saying that's the ideal way to do it, but solvable in userland and without modifying the base class. On Thursday, July 19, 2018, Isiah Meadows wrote:

Re: Promise capability support

2018-07-19 Thread Isiah Meadows
For code that high level, I don't even usually deal with promises in the first place except when fetching data, saving data, and awaiting renders and transforms (sometimes). Raw event handlers are good enough for pretty much everything else, and when they aren't, you're almost certainly dealing wit

Re: Promise capability support

2018-07-19 Thread Isiah Meadows
First, I do get that not all uses of deferred-like objects really merit the need for a deferred. For example, [here][1], I saved the resolver and pulled the state out from the main closure to make the state easier to follow. You could argue a deferred isn't really necessary since I only care about

Re: Promise capability support

2018-07-19 Thread kai zhu
my use-case is the exact opposite. in integration-level javascript, its impractical to have independent rejectors/error-handlers for dozens of integrated-components. its much easier to debug/refactor integration-code with a single, universal rejector/error-handler (all it does is log the error-st

Re: Promise capability support

2018-07-19 Thread Bob Myers
I've used this pattern exactly twice in the large-scale app I'm working on now. One of those I was able to eliminate after I thought harder about the problem. The other I eventually replaced with the following kind of pattern: ``` function createPromise(resolver, rejector) { return new Promise((

Re: Promise capability support

2018-07-19 Thread Jordan Harband
I don't think the Deferred pattern is a good primitive to have in the language, and it's a pretty trivial primitive to write yourself if you need it. On Thu, Jul 19, 2018 at 6:13 PM, Isiah Meadows wrote: > Sometimes, it's *very* convenient to have those `resolve`/`reject` > functions as separate