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

fix($parse): make promise unwrapping opt-in #4317

Merged
merged 2 commits into from
Oct 9, 2013

Conversation

IgorMinar
Copy link
Contributor

Previously promises found anywhere in the expression during expression
evaluation would evaluate to undefined while unresolved and to the
fulfillment value if fulfilled.

This is a feature that didn't prove to be wildly useful or popular,
primarily because of the dichotomy between data access in templates
(accessed as raw values) and controller code (accessed as promises).

In most code we ended up resolving promises manually in controllers
anyway and thus unifying the model access there.

Other downsides of automatic promise unwrapping:

  • when building components it's often desirable to receive the
    raw promises
  • adds complexity and slows down expression evaluation
  • makes expression code pre-generation unattractive due to the
    amount of code that needs to be generated
  • makes IDE auto-completion and tool support hard
  • adds too much magic

Closes #4158
Closes #4270

@mary-poppins
Copy link

Thanks for the PR!

  • Contributor signed CLA now or in the past
    • If you just signed, leave a comment here with your real name
  • PR's commit messages follow the commit message format

If you need to make changes to your pull request, you can update the commit with git commit --amend.
Then, update the pull request with git push -f.

Thanks again for your help!

@wilsonjackson
Copy link

Thanks @IgorMinar, this does seem like the most sensible solution.

@mhevery
Copy link
Contributor

mhevery commented Oct 9, 2013

LGTM

This commit disables promise unwrapping and adds
$parseProvider.unwrapPromises() getter/setter api that allows developers
to turn the feature back on if needed. Promise unwrapping support will
be removed from Angular in the future and this setting only allows for
enabling it during transitional period.

If the unwrapping is enabled, Angular will log a warning about each
expression that unwraps a promise (to reduce the noise, each expression
is logged only onces). To disable this logging use
`$parseProvider.logPromiseWarnings(false)`.

Previously promises found anywhere in the expression during expression
evaluation would evaluate to undefined while unresolved and to the
fulfillment value if fulfilled.

This is a feature that didn't prove to be wildly useful or popular,
primarily because of the dichotomy between data access in templates
(accessed as raw values) and controller code (accessed as promises).

In most code we ended up resolving promises manually in controllers
or automatically via routing and unifying the model access in this way.

Other downsides of automatic promise unwrapping:

- when building components it's often desirable to receive the
  raw promises
- adds complexity and slows down expression evaluation
- makes expression code pre-generation unattractive due to the
  amount of code that needs to be generated
- makes IDE auto-completion and tool support hard
- adds too much magic

BREAKING CHANGE: $parse and templates in general will no longer
automatically unwrap promises. This feature has been deprecated and
if absolutely needed, it can be reenabled during transitional period
via `$parseProvider.unwrapPromises(true)` api.

Closes angular#4158
Closes angular#4270
This reverts commit 3a65822.

The change cased regressions in third party components that require
promises from getter functions not to be unwrapped.

Since we have deprecated the promise unwrapping support in $parse it
doesn't make much sense to fix this issue and deal with regressions in
third party code.

Closes angular#4158
@IgorMinar IgorMinar merged commit 4c112f5 into angular:master Oct 9, 2013
@clakech
Copy link
Contributor

clakech commented Oct 29, 2013

Too bad :(

This will lead to an increase number of line of code in our controller to resolve promises using then/always stuff AND there is no way in angular to deal with race condition if you resolve multiple time a promise but you only want to keep first/last/specific result

This 'magic' was good in my opinion and I would like to know what other native angular feature you will remove in short term that we already use widely in our codebase.

Thank you for all the refactoring stuff I will have to do soon ;-)

rodyhaddad added a commit to rodyhaddad/angular.js that referenced this pull request May 22, 2014
The feature has been deprecated in angular#4317

BREAKING CHANGE: promise unwrapping has been removed.
It can no longer be turned on.
Two methods have been removed:
* $parseProvider.unwrapPromises
* $parseProvider.logPromiseWarnings
rodyhaddad added a commit to rodyhaddad/angular.js that referenced this pull request May 23, 2014
The feature has been deprecated in angular#4317

BREAKING CHANGE: promise unwrapping has been removed.
It has been deprecated since 1.2.0-rc.3.

It can no longer be turned on.
Two methods have been removed:
* $parseProvider.unwrapPromises
* $parseProvider.logPromiseWarnings
rodyhaddad added a commit to rodyhaddad/angular.js that referenced this pull request May 23, 2014
The feature has been deprecated in angular#4317

BREAKING CHANGE: promise unwrapping has been removed.
It has been deprecated since 1.2.0-rc.3.

It can no longer be turned on.
Two methods have been removed:
* $parseProvider.unwrapPromises
* $parseProvider.logPromiseWarnings
rodyhaddad added a commit to rodyhaddad/angular.js that referenced this pull request May 23, 2014
The feature has been deprecated in angular#4317

BREAKING CHANGE: promise unwrapping has been removed.
It has been deprecated since 1.2.0-rc.3.

It can no longer be turned on.
Two methods have been removed:
* $parseProvider.unwrapPromises
* $parseProvider.logPromiseWarnings
RichardLitt pushed a commit to RichardLitt/angular.js that referenced this pull request May 24, 2014
The feature has been deprecated in angular#4317

BREAKING CHANGE: promise unwrapping has been removed.
It has been deprecated since 1.2.0-rc.3.

It can no longer be turned on.
Two methods have been removed:
* $parseProvider.unwrapPromises
* $parseProvider.logPromiseWarnings
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatic unwrapping of promises by $parse severely limits its usefulness
5 participants