operation.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. 'use strict';
  6. CKEDITOR.define( [], function() {
  7. /**
  8. * Abstract base operation class.
  9. *
  10. * @abstract
  11. * @class document.operation.Operation
  12. */
  13. class Operation {
  14. /**
  15. * Base operation constructor.
  16. *
  17. * @param {Number} baseVersion {@link document.Document#version} on which the operation can be applied.
  18. * @constructor
  19. */
  20. constructor( baseVersion ) {
  21. /**
  22. * {@link document.Document#version} on which operation can be applied. If you try to
  23. * {@link document.Document#applyOperation apply} operation with different base version than the
  24. * {@link document.Document#version document version} the {@link document-applyOperation-wrong-version}
  25. * error is thrown.
  26. *
  27. * @property {Number}
  28. */
  29. this.baseVersion = baseVersion;
  30. /**
  31. * Executes the operation - modifications described by the operation attributes
  32. * will be applied to the tree model.
  33. *
  34. * @method _execute
  35. * @protected
  36. */
  37. /**
  38. * Creates and returns a reverse operation. Reverse operation when executed right after
  39. * the original operation will bring back tree model state to the point before the original
  40. * operation execution. In other words, it reverses changes done by the original operation.
  41. *
  42. * Keep in mind that tree model state may change since executing the original operation,
  43. * so reverse operation will be "outdated". In that case you will need to
  44. * {@link #getTransformedBy transform} it by all operations that were executed after the original operation.
  45. *
  46. * @method getReversed
  47. * @returns {document.operation.Operation} Reversed operation.
  48. */
  49. /**
  50. * Creates and returns a clone of this operation which is transformed by the given operation.
  51. * When operation is transformed its parameters may change accordingly to the operation which it is
  52. * transformed by. If the given operation applied to the tree model any modifications which are
  53. * affecting ranges/positions/nodes connected with this operation, those changes will be reflected
  54. * in the parameters of the returned operation.
  55. *
  56. * Whenever the {@link document.Document document} has different {@link document.Document#baseVersion}
  57. * than an operation you want to {@link document.Document#applyOperation apply}, you need to transform
  58. * all the operations that were executed on the {@link document.Document document} since it has
  59. * {@link document.Document#baseVersion} same as the operation (transform in the same order as those
  60. * operations were executed). This way all modifications done to the tree model will be reflected
  61. * in the operation parameters and the operation will "work" on "up-to-date" version of the tree model.
  62. *
  63. * **TODO**: So far we think that transforming one operation by another one may result in more than one
  64. * operation. This needs to be clarified in this documentation.
  65. *
  66. * @method getTransformedBy
  67. * @param {document.operation.Operation} operation Operation by which this operation will be transformed.
  68. * @returns {document.operation.Operation[]} A result of transformation of this operation by the given operation.
  69. */
  70. }
  71. }
  72. return Operation;
  73. } );