Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat($timeout): overload service API. #9723

Closed
wants to merge 1 commit into from

Conversation

vasileorza
Copy link
Contributor

Provided an overload for $timeout that doesn't take a function.

Closes #9176

@mary-poppins
Copy link

I'm sorry, but I wasn't able to verify your Contributor License Agreement (CLA) signature. CLA signature is required for any code contributions to AngularJS.

Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match.

If you signed the CLA as a corporation, please let us know the company's name.

Thanks a bunch!

PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR.
PS2: If you are a Googler, please sign the CLA as well to simplify the CLA verification process.

@gkalpak
Copy link
Member

gkalpak commented Oct 21, 2014

I don't really see the benefit.

Instead of writing $timeout(callback, delay), we will be able to write $timeout(delay).then(callback).
What's the point (it's even more verbose) ?

@rodyhaddad
Copy link
Contributor

CLA verified in person, cc @jeffbcross

Provide an overload for $timeout that doesn't take a function.

Closes angular#9176
} else {
fn = noop,
delay = arguments[0],
invokeApply = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if invokeApply is defined when calling $timeout, then it should be respected. BTW, if the default changes when defining or not a function, then the documentation needs to be updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the default changes, then we're not landing it --- jus saying, that is a really pointless breaking change. But it shouldn't change if your comment is addressed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, @vasileorza please don't do the arguments[0] etc thing --- use named formal parameters instead, it is so much easier to read

@petebacondarwin
Copy link
Contributor

@gkalpak - I guess the benefit is that you might just want to create a promise that is passed elsewhere; the creator of the timeout might not be attaching any callback at all.

@petebacondarwin
Copy link
Contributor

I think we can merge this - eventually. We need to check the CLA and ensure there are definitely no related regressions or breaking changes.

@caitp
Copy link
Contributor

caitp commented Oct 23, 2014

I think regressions are unlikely in this case, and it's hard to see what the breaking change would be if comments are addressed.

The invokeaApply -> false if there's no callback thing is weird, lets leave invokeApply the way it is.

It should be more like

if (typeof fn === 'number') {
  invokeApply = delay;
  delay = fn;
  fn = noop;
}

And then only invoke fn if it's a function

@mary-poppins
Copy link

CLA signature verified! Thank you!

Someone from the team will now triage your PR and it will be processed based on the determined priority (doc updates and fixes with tests are prioritized over other changes).

@gkalpak
Copy link
Member

gkalpak commented Oct 23, 2014

@petebacondarwin: $timeout does already return a promise, so you can just do:

$timeout(angular.noop, <delay>)

So, this deoesn't really add any new feature, it is just syntactic sugar.
Not that I have something against syntactic sugar, but I (still) can't see any benefit.
I can only imagine people abusing this, just to put an arbitrary delay to "make sure something has done its thing" (which is usually (read "always") a bad practice).

Not that it wasn't possible before, but this new syntax is like "asking for it".
Just my two (cranky) cents :)

@petebacondarwin
Copy link
Contributor

I fixed up the PR and landed - thanks @vasileorza for the work; and @caitp, @lgalfaso and @gkalpak for the reviewing.

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

Successfully merging this pull request may close these issues.

Provide an overload for $timeout that doesn't take a function
7 participants