mirror of
https://github.com/nasa/openmct.git
synced 2025-06-20 08:03:49 +00:00
Merge pull request #317 from nasa/open316
[bug] TypeImpl.getInitialmodel should always return a fresh (ie. cloned) model.
This commit is contained in:
@ -156,8 +156,15 @@ define(
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the default model for an object of this type. Note that
|
||||||
|
* this method returns a clone of the original model, so if using this
|
||||||
|
* method heavily, consider caching the result to optimize performance.
|
||||||
|
*
|
||||||
|
* @return {object} The default model for an object of this type.
|
||||||
|
*/
|
||||||
TypeImpl.prototype.getInitialModel = function () {
|
TypeImpl.prototype.getInitialModel = function () {
|
||||||
return this.typeDef.model || {};
|
return JSON.parse(JSON.stringify(this.typeDef.model || {}));
|
||||||
};
|
};
|
||||||
|
|
||||||
TypeImpl.prototype.getDefinition = function () {
|
TypeImpl.prototype.getDefinition = function () {
|
||||||
|
@ -101,6 +101,12 @@ define(
|
|||||||
expect(type.getInitialModel().someKey).toEqual("some value");
|
expect(type.getInitialModel().someKey).toEqual("some value");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("provides a fresh initial model each time", function () {
|
||||||
|
var model = type.getInitialModel();
|
||||||
|
model.someKey = "some other value";
|
||||||
|
expect(type.getInitialModel().someKey).toEqual("some value");
|
||||||
|
});
|
||||||
|
|
||||||
it("provides type properties", function () {
|
it("provides type properties", function () {
|
||||||
expect(type.getProperties().length).toEqual(1);
|
expect(type.getProperties().length).toEqual(1);
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user