Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should we support optional variants of eventual methods? #18

Open
JLHwung opened this issue Nov 13, 2020 · 0 comments
Open

Should we support optional variants of eventual methods? #18

JLHwung opened this issue Nov 13, 2020 · 0 comments

Comments

@JLHwung
Copy link

JLHwung commented Nov 13, 2020

For example they can default to the optional access, or for delegated promises, calling the associated handler trap.

Static Method Default Behavior Handler trap
eventualOptionalGet(p, prop) p.then(t => t?.[prop]) h.eventualOptionalGet(t, prop)
eventualOptionalApply(p, args) p.then(t => t?.(...args)) h.eventualOptionalApply(t, args)
eventualOptionalSend(p, prop, args) p.then(t => t?.[prop](...args)) h.eventualOptionalSend(t, prop, args)

Note that for eventualOptionalSend, there are two optional behaviours, though the usage is expected less common

p.then(t => t?.[prop]?.(...args));
p.then(t => t[prop]?.(...args));

Alternatively, users could provide own handler for such behavior, likewise for other methods.

{
  eventualGet(target, prop) {
    return target?.prop
  },
  eventualApply(target, args) {
    return target?.(...args)
  },
  eventualSend(target, prop, args) {
    return target?.prop(...args)
  }
}

But given that optional chaining is very handy on error processing, it would encourage the usage of handler traps for such a simple use case, which I think is a bad practice.

The broader question behind this one, is in what extent the eventual should methods map to the LeftHandSideExpression. The current eventual methods covers common operation like
some productions of call expression

CallExpression:
  PrimaryExpression ( Arguments );
  PrimaryExpression [ Expression ] ( Arguments );
  PrimaryExpression . IdentifierName ( Arguments );

and some productions of member expression

MemberExpression:
  PrimaryExpression [ Expression ];
  PrimaryExpression . IdentifierName

The OptionalExpression is not mapped by any event traps, nor is NewExpression (#19) or nested member/call expressions (tc39/proposal-wavy-dot#10, tc39/proposal-wavy-dot#11).

Related: tc39/proposal-wavy-dot#8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant