operationfactory.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /**
  6. * @module engine/model/operation/operationfactory
  7. */
  8. import AttributeOperation from '../operation/attributeoperation';
  9. import InsertOperation from '../operation/insertoperation';
  10. import MarkerOperation from '../operation/markeroperation';
  11. import MoveOperation from '../operation/moveoperation';
  12. import NoOperation from '../operation/nooperation';
  13. import Operation from '../operation/operation';
  14. import ReinsertOperation from '../operation/reinsertoperation';
  15. import RemoveOperation from '../operation/removeoperation';
  16. import RenameOperation from '../operation/renameoperation';
  17. import RootAttributeOperation from '../operation/rootattributeoperation';
  18. const operations = {};
  19. operations[ AttributeOperation.className ] = AttributeOperation;
  20. operations[ InsertOperation.className ] = InsertOperation;
  21. operations[ MarkerOperation.className ] = MarkerOperation;
  22. operations[ MoveOperation.className ] = MoveOperation;
  23. operations[ NoOperation.className ] = NoOperation;
  24. operations[ Operation.className ] = Operation;
  25. operations[ ReinsertOperation.className ] = ReinsertOperation;
  26. operations[ RemoveOperation.className ] = RemoveOperation;
  27. operations[ RenameOperation.className ] = RenameOperation;
  28. operations[ RootAttributeOperation.className ] = RootAttributeOperation;
  29. /**
  30. * A factory class for creating operations.
  31. *
  32. * @abstract
  33. */
  34. export default class OperationFactory {
  35. /**
  36. * Creates concrete `Operation` object from deserilized object, i.e. from parsed JSON string.
  37. *
  38. * @param {Object} json Deserialized JSON object.
  39. * @param {module:engine/model/document~Document} document Document on which this operation will be applied.
  40. * @returns {module:engine/model/operation/operation~Operation}
  41. */
  42. static fromJSON( json, document ) {
  43. return operations[ json.__className ].fromJSON( json, document );
  44. }
  45. }