Merge pull request #317 from nasa/open316

[bug] TypeImpl.getInitialmodel should always return a fresh (ie. cloned) model.
This commit is contained in:
Victor Woeltjen 2015-11-18 12:21:23 -08:00
commit a7f277b0d2
2 changed files with 14 additions and 1 deletions

View File

@ -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 () {
return this.typeDef.model || {};
return JSON.parse(JSON.stringify(this.typeDef.model || {}));
};
TypeImpl.prototype.getDefinition = function () {

View File

@ -101,6 +101,12 @@ define(
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 () {
expect(type.getProperties().length).toEqual(1);
});