Forráskód Böngészése

Added custom toJSON method for core.treeModel.operation.Operation.

Szymon Cofalik 9 éve
szülő
commit
9eed23013d

+ 17 - 0
packages/ckeditor5-engine/src/treemodel/operation/operation.js

@@ -5,6 +5,8 @@
 
 'use strict';
 
+import clone from '../../lib/lodash/clone.js';
+
 /**
  * Abstract base operation class.
  *
@@ -71,4 +73,19 @@ export default class Operation {
 		 * property containing changed nodes. May have additional properties depending on the operation type.
 		 */
 	}
+
+	/**
+	 * Custom toJSON method to solve child-parent circular dependencies.
+	 *
+	 * @method core.treeModel.operation.Operation#toJSON
+	 * @returns {Object} Clone of this object with the delta property replaced with string.
+	 */
+	toJSON() {
+		const json = clone( this );
+
+		// Due to circular references we need to remove parent reference.
+		json.delta = this.delta ? '[core.treeModel.Delta]' : null;
+
+		return json;
+	}
 }