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

Keep option to unwrap promises in template #5153

Closed
@lyschoening

Description

@lyschoening

This issue regards the previously closed issues #4158 and #4270. As I understand, unwrapping promises is now deprecated and on track for quick removal since unwrapPromises is clearly not intended to be much more than a helper for upgrading.

This recent change affects much of the code base of my application, which is heavy on nested promises that cannot be easily resolved with an unwrap() function as suggested in #4158. I think the change breaks AngularJS for many use cases that were not considered so far. I very much hope that a workable option for automatic unwrapping is (re)introduced before the deprecation becomes final.

While resolving one level of promises in the controller is already quite cumbersome (via e.g. promiseX.then (x) $scope.x = x for one item), it becomes impossibly complex with patterns as you might use with hierarchical or graph data structures:

  • Nested promises
  • Lazy loading via Object.defineProperty
  • Function calls in the template

Whenever you have nested promises, you either need to block while you resolve all promises; or have controllers with every single ng-repeat that do nothing more than resolve promises and copy them into the scope (e.g. ($scope) -> $scope.a.b.then (b) -> $scope.aB = b). As far as I know, AngularJS doesn't even provide a good helper function for resolving nested promises.

An unwrap() function is no solution, because you can't write something like unwrap(item).name in the template. You have to write a controller that blocks the expression from rendering until the promise is resolved, or at the very least insert ng-if="unwrap(promise)" on those tags that make use of a promise. On the other hand, it would have been very possible to write a wrap(promise) function that prevents a promise from resolving, if preventing automatic resolution was the objective of #4158.

I very much hope that a workable option for automatic unwrapping is (re)introduced before the deprecation becomes final.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions