diff --git a/platform/core/src/types/TypeImpl.js b/platform/core/src/types/TypeImpl.js index deb23873e5..333f37663f 100644 --- a/platform/core/src/types/TypeImpl.js +++ b/platform/core/src/types/TypeImpl.js @@ -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 () { diff --git a/platform/core/test/types/TypeImplSpec.js b/platform/core/test/types/TypeImplSpec.js index d29c4f2712..0203058934 100644 --- a/platform/core/test/types/TypeImplSpec.js +++ b/platform/core/test/types/TypeImplSpec.js @@ -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); });