mirror of
https://github.com/nasa/openmct.git
synced 2024-12-23 23:12:23 +00:00
Merge remote-tracking branch 'origin/open931' into open-master
This commit is contained in:
commit
828f82a3e7
@ -157,8 +157,7 @@
|
||||
},
|
||||
{
|
||||
"key": "mutation",
|
||||
"implementation": "capabilities/MutationCapability.js",
|
||||
"depends": [ "$q" ]
|
||||
"implementation": "capabilities/MutationCapability.js"
|
||||
},
|
||||
{
|
||||
"key": "delegation",
|
||||
|
@ -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
|
||||
@ -36,12 +46,11 @@ define(
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @param $q Angular's $q service, for promises
|
||||
* @param {DomainObject} domainObject the domain object
|
||||
* which will expose this capability
|
||||
* @constructor
|
||||
*/
|
||||
function MutationCapability($q, domainObject) {
|
||||
function MutationCapability(domainObject) {
|
||||
|
||||
function mutate(mutator) {
|
||||
// Get the object's model and clone it, so the
|
||||
@ -73,8 +82,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 {
|
||||
|
@ -13,21 +13,9 @@ define(
|
||||
domainObject = { getModel: function () { return testModel; } },
|
||||
mutation;
|
||||
|
||||
function mockPromise(value) {
|
||||
return {
|
||||
then: function (callback) {
|
||||
return (value && value.then) ?
|
||||
value : mockPromise(callback(value));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
testModel = { number: 6 };
|
||||
mutation = new MutationCapability(
|
||||
{ when: mockPromise }, // $q
|
||||
domainObject
|
||||
);
|
||||
mutation = new MutationCapability(domainObject);
|
||||
});
|
||||
|
||||
it("allows mutation of a model", function () {
|
||||
|
Loading…
Reference in New Issue
Block a user