Giter VIP home page Giter VIP logo

Comments (12)

pkozlowski-opensource avatar pkozlowski-opensource commented on July 22, 2024

This suggests opposite thing to #56293

from angular.

haqer1 avatar haqer1 commented on July 22, 2024

This suggests opposite thing to #56293

Yes, i had just thought of tooling diagnostic error detecting this as alternative, but turns out this had already been suggested 18 hours ago.
These are not 100% exclusive.

The quirk suggested there[1], could be treated as suggested there, whereas defaulted calling could come from here.

P.S.
[1]

<button (click)="void incrementAndLaterDecrement()">Increment</button>

<button (click)="incrementAndLaterDecrement();">Increment</button>

from angular.

haqer1 avatar haqer1 commented on July 22, 2024

One could even consider combining defaulted calling from here with a diagnostic warning (rather than error suggested in #56293)

from angular.

JoostK avatar JoostK commented on July 22, 2024

Extended diagnostics are configurable w.r.t. being an error, warning or skipped altogether.

from angular.

haqer1 avatar haqer1 commented on July 22, 2024

OK, i updated my comment to mention warning only for now.

P.S. Although info could be another feature. :)

from angular.

haqer1 avatar haqer1 commented on July 22, 2024

I updated Alternatives considered section in the OP, to make the issue more legible.

from angular.

alxhub avatar alxhub commented on July 22, 2024

I think an extended diagnostic is probably the right answer here.

Trying to detect whether an expression in an event listener should be auto-called by the framework is a blurry proposition. For example:

(foo)="bar" // probably meant to call it
(foo)="bar.baz" // probably meant to be a call, but also is a method tearoff if strictly interpreted
(foo)="a && b" // also a side-effect free expression, but did you mean (a && b)() or a() && b()
(foo)="getCallback()" // you probably wanted getCallback()() but that's super hard to infer

Instead, I think it's better to report an error when we detect that an expression evaluates to a callable type but is not called.

from angular.

haqer1 avatar haqer1 commented on July 22, 2024

I updated Alternatives considered section in the OP, to make the issue more legible.

Twice.

from angular.

haqer1 avatar haqer1 commented on July 22, 2024

That's why i've been saying they are not 100% exclusive. Considering continuum of 4 approaches i listed in Alternatives considered in the OP a few minutes ago:

(foo)="bar" // probably meant to call it

approach 1.

ts (foo)="bar.baz" // probably meant to be a call, but also is a method tearoff if strictly interpreted

iff you are saying we can't reliably conclude that this means bar.baz() (but is there a real use-case of that?), (then it won't be approach 1.,) but (rather can be) approach 4.

(foo)="a && b" // also a side-effect free expression, but did you mean (a && b)() or a() && b()

approach 4.

(foo)="getCallback()" // you probably wanted getCallback()() but that's super hard to infer

That's a separate issue out of scope of this issue (because there are "()"), but mentioned as a quirk previously (#56305 (comment)): it's treatment should be discussed separately (should probably even be split off of #56293, because it's not the main thing discussed there, but a fringe case).

from angular.

haqer1 avatar haqer1 commented on July 22, 2024

Although not exactly the same, i'd like to point out that lambda expressions, method calls & just function names can work equivalently in standard JS. E.g.,
a. https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event#examples

function doSomething() {
  console.info("DOM loaded");
}

if (document.readyState === "loading") {
  // Loading hasn't finished yet
  document.addEventListener("DOMContentLoaded", doSomething);
} else {
  // `DOMContentLoaded` has already fired
  doSomething();
}

b. https://jsfiddle.net/haqer/8Lpganh5/76/

document.getElementById("add").addEventListener("click", handleNew);

from angular.

haqer1 avatar haqer1 commented on July 22, 2024

Different area, but perhaps there is a similarity in this seeming example of approach 2 from gpg domain:

gpg -o test.pdf test.pdf.gpg
gpg: WARNING: no command supplied.  Trying to guess what you mean ...
...
File 'test.pdf' exists. Overwrite? (y/N) y
...

P.S. The similarity is in automated deducted action (in this case with a notification).

from angular.

JeanMeche avatar JeanMeche commented on July 22, 2024

Like it been pointed, we're choosing to go in the opposite direction cf #56293 (WIP implementation #56295).

Also the example about addEventListener is different. It expect a function, not something you could or not invoke.

from angular.

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.