cleans up can.Compute.read and adds template-obserbable promises #1540
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For #179, this makes promises observable when read by
can.Compute.read
.Promises in the template.
This powers promises in the template like:
This should work with any promise that passes can.isPromise. Currently, only objects with
.then
and.pipe
are considered promises. Users can overwrite this to be more permissive.The following properties on a promise are available:
isResolved
istrue
.isRejected
istrue
This only makes promises observable in a template. If you were to use a promise in a compute, it will not re-evaluate the compute when the promise changes. However, with async getters and setters, you can wire up changes in the observable state to changes in a value yourself.
Changes to can.Compute.read
can.Compute.read
is moved into its own file: compute/read.js. It also is designed to be a bit more extensible. The read function uses a list ofvalueReaders
andpropertyReaders
to read the properties fromparent
.valueReaders
are used for things like functions and computes, which do not have a property to read.propertyReaders
are used to read properties on an object, can.Map and now promise.This change allows us to provide multiple ways to translate the DOT operator into specific ways of reading values for the template.
In the future, I think we should make
can.compute(parent, "foo.bar")
usecan.Compute.read
. This would allow:where map's "promise" attribute is a promise that returns another map that has a "first" attribute which is a map with a "name" attribute.