[Core] Accelerate promises during mutation

Use a fast-promise approach (instead of ) when handling
mutation of domain objects, to ensure that mutation resolves
during the current tick. Needed for drag interactions of
WTD-931.
This commit is contained in:
Victor Woeltjen
2015-03-11 17:37:07 -07:00
parent b05315a140
commit 00daa32f56

View File

@ -21,6 +21,16 @@ define(
}); });
} }
// Utility function to cast to a promise, without waiting
// for nextTick if a value is non-promise-like.
function fastPromise(value) {
return (value || {}).then ? value : {
then: function (callback) {
return fastPromise(callback(value));
}
};
}
/** /**
* The `mutation` capability allows a domain object's model to be * The `mutation` capability allows a domain object's model to be
* modified. Wrapping such modifications in calls made through * modified. Wrapping such modifications in calls made through
@ -73,8 +83,7 @@ define(
// Invoke the provided mutator, then make changes to // Invoke the provided mutator, then make changes to
// the underlying model (if applicable.) // the underlying model (if applicable.)
return $q.when(mutator(clone)) return fastPromise(mutator(clone)).then(handleMutation);
.then(handleMutation);
} }
return { return {