[Edit] Utilize model cache

Utilize model cache, permitting object models in edit mode to
be reused across multiple distinct instances with unique
contexts (unique contexts are necessary to avoid ambiguity in
the Remove action, WTD-473).

To avoid infinite digest cycles as a consequence of this,
refactor context/composition capability wrappers such that the
former is idempotent (since idempotence is no longer ensured
by the EditableDomainObjectCache) to avoid infinite digest
errors in Edit mode.
This commit is contained in:
Victor Woeltjen
2015-01-27 11:52:58 -08:00
parent 431af3adbc
commit 3135174491
5 changed files with 154 additions and 60 deletions

View File

@ -53,9 +53,8 @@ define(
// Constructor for EditableDomainObject, which adheres
// to the same shared cache.
function EditableDomainObjectImpl(domainObject) {
var model = JSON.parse(JSON.stringify(domainObject.getModel())),
editableObject = Object.create(domainObject);
function EditableDomainObjectImpl(domainObject, model) {
var editableObject = Object.create(domainObject);
// Only provide the cloned model.
editableObject.getModel = function () { return model; };

View File

@ -15,7 +15,8 @@
* @module editor/object/editable-domain-object-cache
*/
define(
function () {
["./EditableModelCache"],
function (EditableModelCache) {
'use strict';
/**
@ -32,7 +33,7 @@ define(
* @memberof module:editor/object/editable-domain-object-cache
*/
function EditableDomainObjectCache(EditableDomainObject) {
var cache = {},
var cache = new EditableModelCache(),
dirty = {};
return {
@ -44,9 +45,10 @@ define(
* @returns {DomainObject} the domain object in an editable form
*/
getEditableObject: function (domainObject) {
var id = domainObject.getId();
return (cache[id] =
cache[id] || new EditableDomainObject(domainObject));
return new EditableDomainObject(
domainObject,
cache.getCachedModel(domainObject)
);
},
/**
* Mark an editable domain object (presumably already cached)