From 00daa32f56ca56b37ec3347bed02d589f2887226 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 11 Mar 2015 17:37:07 -0700 Subject: [PATCH] [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. --- .../core/src/capabilities/MutationCapability.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/platform/core/src/capabilities/MutationCapability.js b/platform/core/src/capabilities/MutationCapability.js index d0d6c2b360..14ff3a5265 100644 --- a/platform/core/src/capabilities/MutationCapability.js +++ b/platform/core/src/capabilities/MutationCapability.js @@ -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 * modified. Wrapping such modifications in calls made through @@ -73,8 +83,7 @@ define( // Invoke the provided mutator, then make changes to // the underlying model (if applicable.) - return $q.when(mutator(clone)) - .then(handleMutation); + return fastPromise(mutator(clone)).then(handleMutation); } return {