mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 14:18:16 +00:00
[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:
@ -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 {
|
||||||
|
Reference in New Issue
Block a user